atcoder#ABC270D. [ABC270D] Stones
[ABC270D] Stones
Score : points
Problem Statement
Takahashi and Aoki will play a game of taking stones using a sequence .
There is a pile that initially contains stones. The two players will alternately perform the following operation, with Takahashi going first.
- Choose an that is at most the current number of stones in the pile. Remove stones from the pile.
The game ends when the pile has no stones.
If both players attempt to maximize the total number of stones they remove before the end of the game, how many stones will Takahashi remove?
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
10 2
1 4
5
Below is one possible progression of the game.
- Takahashi removes stones from the pile.
- Aoki removes stones from the pile.
- Takahashi removes stone from the pile.
- Aoki removes stone from the pile.
In this case, Takahashi removes stones. There is no way for him to remove or more stones, so this is the maximum.
Below is another possible progression of the game where Takahashi removes stones.
- Takahashi removes stone from the pile.
- Aoki removes stones from the pile.
- Takahashi removes stones from the pile.
- Aoki removes stone from the pile.
11 4
1 2 3 6
8
Below is one possible progression of the game.
- Takahashi removes stones.
- Aoki removes stones.
- Takahashi removes stones.
In this case, Takahashi removes stones. There is no way for him to remove or more stones, so this is the maximum.
10000 10
1 2 4 8 16 32 64 128 256 512
5136