#P1459. [IOI 1996 / USACO2.1] 三值的排序 Sorting a Three-Valued Sequence
[IOI 1996 / USACO2.1] 三值的排序 Sorting a Three-Valued Sequence
Description
Sorting is a frequent computational task. Now consider sorting when there are at most three possible values. A practical example is ranking winners of a competition by gold, silver, and bronze medals. In this task, the possible values are only . We use swaps to arrange the sequence in ascending order.
Write a program to compute the minimum number of swaps needed to sort a given sequence consisting only of into ascending order.
Input Format
The first line contains a positive integer , the number of medals.
Each of the next lines contains an integer in , representing a medal.
Output Format
Output a single integer, the minimum number of swaps needed to sort the sequence in ascending order.
9
2
2
1
3
3
3
2
3
1
4
Hint
Constraints
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号