#P7650. [BalticOI 2007] Ranklist Sorting (Day 1)
[BalticOI 2007] Ranklist Sorting (Day 1)
Description
In a contest, you are given the scores of several players. Your task is to create a ranklist of the players sorted by decreasing score.
Unfortunately, the data structure used for the ranklist supports only one operation: move a player from position to position without changing the relative order of the other players. If , then the players in positions between and increase their positions by ; otherwise, if , then the players in positions between and decrease their positions by .
This operation takes steps to locate the player to be moved, and steps to locate the position to move him or her to, so the total cost of moving a player from position to position is . Positions are numbered starting from .
Determine a sequence of moves to create the ranklist such that the sum of move costs is minimized.
Input Format
The first line contains an integer , the number of players.
Each of the next lines contains a non-negative integer , the score of a player in the current order. You may assume that all scores are distinct.
Output Format
Output the number of moves used to create the ranklist on the first line. The following lines should specify the moves in the order they are applied. Each move should be described on one line containing two integers and , meaning that the player at position is moved to position . The numbers and must be separated by a single space.
5
20
30
5
15
10
2
2 1
3 5
Hint
Constraints
For of the testdata, , .
For of the testdata, , .
Notes
From Baltic Olympiad in Informatics 2007, Day 1:sorting.
Translated and organized by @求学的企鹅.
Translated by ChatGPT 5
京公网安备 11011102002149号