atcoder#ABC263F. [ABC263F] Tournament
[ABC263F] Tournament
Score : points
Problem Statement
people, numbered to , will participate in a rock-paper-scissors tournament.
The tournament proceeds as follows:
- The participants are arranged in a row in the order Person , Person , , Person from left to right.
- Let be the current length of the row. For each , the -th and -th persons from the left play a game against each other. Then, the losers are removed from the row. This process is repeated times.
Here, if Person wins exactly games, they receive yen (Japanese currency). A person winning zero games receives nothing. Find the maximum possible total amount of money received by the people if the results of all games can be manipulated freely.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
2
2 5
6 5
2 1
7 9
15
The initial row of the people is .
If Person wins the game against Person , and Person wins the game against Person , the row becomes .
Then, if Person wins the game against Person , the row becomes , and the tournament ends.
Here, Person wins exactly game, and Person wins exactly games, so they receive yen in total, which is the maximum possible sum.
3
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
4