atcoder#CF17EXHIBITIONB. Increment and Swap
Increment and Swap
Score : points
Problem Statement
We have a sequence of length .
On this sequence, we can perform the following two kinds of operations:
- Swap two adjacent elements.
- Select one element, and increment it by .
We will repeatedly perform these operations so that will be a non-decreasing sequence. Find the minimum required number of operations.
Constraints
- is an integer.
Input
Input is given from Standard Input in the following format:
Output
Print the minimum number of operations required to turn into a non-decreasing sequence.
5
4
1
8
8
7
2
We can turn into a non-decreasing sequence in two operations:
- Initially, .
- Swap the first two elements. Now, .
- Increment the last element by . Now, .
20
8
2
9
7
4
6
7
9
7
4
7
4
4
3
6
2
3
4
4
9
62