atcoder#ARC117F. [ARC117F] Gateau
[ARC117F] Gateau
Score : points
Problem Statement
Mr. AtCoder made a round chocolate cake for his friends. It is radially cut from the center into equal pieces, numbered through in clockwise order.
To give the final touches, he is going to put strawberries on each piece. He has heard what his friends want about it. The friends are numbered through , and Friend wants the following:
- Piece have a total of at least strawberries on them (for , consider Piece as Piece ).
To fulfill the requests of all his friends, at least how many strawberries should be put on the whole cake?
Constraints
- $0 \leq A_i \leq 5 \times 10^8 \ (0 \leq i \leq 2N-1)$
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the minimum number of strawberries that should be put on the whole cake to fulfill the requests of the friends.
3
2 5 7 4 2 1
8
Consider the case we put strawberries on Pieces , respectively.
In this case, all requests of the friends are fulfilled, as follows:
- Friend : Pieces have a total of strawberries on them, which is not less than .
- Friend : Pieces have a total of strawberries on them, which is not less than .
- Friend : Pieces have a total of strawberries on them, which is not less than .
- Friend : Pieces have a total of strawberries on them, which is not less than .
- Friend : Pieces have a total of strawberries on them, which is not less than .
- Friend : Pieces have a total of strawberry on them, which is not less than .
Thus, we can fulfill all requests of the friends by putting a total of strawberries on the cake. This is the minimum number of strawberries needed.
3
8 0 6 0 9 0
12
Consider the case we put strawberries on Pieces , respectively.
In this case, all requests of the friends are fulfilled, as follows:
- Friend : Pieces have a total of strawberries on them, which is not less than .
- Friend : Pieces have a total of strawberries on them, which is not less than .
- Friend : Pieces have a total of strawberries on them, which is not less than .
- Friend : Pieces have a total of strawberries on them, which is not less than .
- Friend : Pieces have a total of strawberries on them, which is not less than .
- Friend : Pieces have a total of strawberries on them, which is not less than .
Thus, we can fulfill all requests of the friends by putting a total of strawberries on the cake. This is the minimum number of strawberries needed.
5
3 1 5 7 0 8 4 6 4 9
12
We can put strawberries on Pieces , respectively, to fulfill all requests of the friends.
In this case, there is a total of strawberries on the cake, which is the minimum number of strawberries needed.
1
267503 601617
869120
We can put strawberries on Piece and strawberries on Piece to fulfill all requests of the friends.
8
418940906 38034755 396064111 43044067 356084286 61548818 15301658 35906016 20933120 211233791 30314875 25149642 42550552 104690843 81256233 63578117
513119404