#2392. A. 鸭子与按钮
A. 鸭子与按钮
Duck Button Game
Background
Shor the Duck is playing a game with his friends on a one-dimensional grid consisting of cells numbered from 1 to left to right.
Problem Description
Each cell has a button. If at any time there are at least ducks on cell , the button on that cell becomes permanently pressed. Even if those ducks leave, the button remains pressed. To win the game, all buttons must be pressed.
Initially, there are ducks on cell 1. In each move, one duck can move one cell to the left or to the right.
Determine the minimum total number of moves required to win the game. It is guaranteed that a solution exists.
Input Format
The input is given from standard input as follows:
Output Format
Output a single integer: the minimum total number of moves needed to win the game.
Sample
2 199
175 42
42
5 3
1 1 0 1 0
3
5 7
2 2 2 2 2
8
7 5
1 3 3 4 5 5 5
30
8 9
7 6 6 6 3 3 3 1
28
8 5
2 3 5 1 4 2 1 0
21
4 1000000000
1 1 1 999999999
2999999997
Constraints
-
For all test cases:
It is guaranteed that a solution exists.
-
Subtasks:
Subtask Score Special Property 1 8 2 5 3 11 4 6 All equal 5 19 6 12 is non-decreasing 7 16 is non-increasing 8 23 None