loj#P3470. 「JOI 2021 Final」集体照
「JOI 2021 Final」集体照
Description
At the end of a training camp, a group photo is taken with the participants. The participants are numbered from to , in order of height. The height of the participant is ().
The participants stand on the stairs for the photo. There are steps in the stairs. The steps are numbered from to , from a lower place to a higher place.
The step is higher than the step by (). Since the steps of the stairs are narrow, only one participant will stand on each step. A group photo will be taken when the participants are lined up behind each other.
A group photo will be taken soon. One participant stands on each step. Now, the participant stands on the step ().
However, since the difference of the heights of the participants are too large, if a photo is taken with the current order of the participants, some participants might be hidden behind other participants. Hence, you want to change the order of the participants so that at least the head of every participant shows on the photo. In other words, the following condition should be satisfied.
- Let be the height of the participant on the step (). Then, the inequality is satisfied for every ().
You can only swap two consecutive participants. In other words, by an operation, you choose a step () arbitrarily, and you swap the participant on the step i and the participant on the step .
You want to minimize the number of operations so that the above condition is satisfied.
Write a program which, given the order of the participants, calculates the minimum number of operations.
Input
Read the following data from the standard input. Given values are all integers.
Output
Write one line to the standard output. The output should contain the minimum number of operations.
5
3 5 2 4 1
3
5
3 2 1 5 4
0
9
6 1 3 4 9 5 7 8 2
9
Constraints
- .
- ().
- ().
Subtasks
- ( points) .
- ( points) .
- ( points) .
- ( points) .
- ( points) No additional constraints.