#ABC479F. 狭窄通道 / Narrow Passage
狭窄通道 / Narrow Passage
Problem Statement
There are people standing on a number line. The people are numbered , and initially person is at coordinate . Here, the are pairwise distinct.
You can repeatedly perform the following operation.
- Choose one person. Let be the coordinate where that person currently is, and move them to or . If there is a person at the destination, that person is simultaneously moved to coordinate .
Find the minimum number of operations required to reach a state where each person is at coordinate . Here, the are pairwise distinct.
Constraints
- and if .
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Output the answer.
3
4 2 5
3 4 1
6
Initially, persons are at coordinates , respectively. By performing the operations as follows, persons end up at coordinates , respectively, in six operations.
- Move person from coordinate to . After this operation, persons are at coordinates , respectively.
- Move person from coordinate to . Since person is at coordinate , person simultaneously moves to coordinate . After this operation, persons are at coordinates , respectively.
- Move person from coordinate to . After this operation, persons are at coordinates , respectively.
- Move person from coordinate to . Since person is at coordinate , person simultaneously moves to coordinate . After this operation, persons are at coordinates , respectively.
- Move person from coordinate to . Since person is at coordinate , person simultaneously moves to coordinate . After this operation, persons are at coordinates , respectively.
- Move person from coordinate to . After this operation, persons are at coordinates , respectively.
4
2 4 5 9
2 4 5 1
11
6
5 2 9 1 6 8
1 4 7 0 9 3
13
- Source: AtCoder ABC 479 F
相关
在下列比赛中: