atcoder#AGC048C. [AGC048C] Penguin Skating
[AGC048C] Penguin Skating
Score : points
Problem Statement
There are squares lining up horizontally in a row, numbered from left to right.
On those squares are penguins, numbered from left to right. Initially, Penguin is on Square . Here, holds.
You can do the following operations any number of times:
- Choose one penguin and slide it to the left or the right. The penguin will keep sliding as long as there is an empty square ahead. It will stop when it reaches a square just before a square occupied by another penguin, or there is no square ahead.
For example, assume that , , and the penguins are on the squares . Here, if we slide Penguin to the right, it will move to Square ; if we slide Penguin to the right, it will move to Square .
Your objective is to put Penguin on Square for every . Here, holds. Determine whether the objective is achievable. If it is achievable, find the minimum number of operations needed.
Constraints
- All numbers in input are integers.
Input
Input is given from Standard Input in the following format:
Output
If the objective is unachievable, print ; if it is achievable, print the minimum number of operations needed.
4 11
3 4 6 10
1 5 6 11
3
The following sequence of operations achieves the objective:
- Slide Penguin to the left. The penguins are now on the squares .
- Slide Penguin to the right. The penguins are now on the squares .
- Slide Penguin to the right. The penguins are now on the squares .
1 3
1
2
-1
10 1000000000
65110170 68805223 123016442 275946481 661490312 760727752 764540566 929355340 930658577 947099792
1 2 123016442 661490311 929355337 930658574 999999997 999999998 999999999 1000000000
13