No.1160 Strange Bowling
Problem Statement
Mitsubachi went bowling on the day of his graduation ceremony to commemorate it.
This bowling game has $N$ turns, and in the $i$-th turn, $p_i$ pins are set up.
In this bowling game, a ball is thrown exactly once in each turn, and a score equal to the number of pins knocked down is given.
Then, if exactly $a_i$ pins are knocked down, the number of pins knocked down in the next turn is added to the score of the $i$-th turn (unless it is the $N$-th turn). The final score is the sum of the scores of all turns.
In fact, Mitsubachi is a professional bowler, so he can knock down any number of pins he likes. What is the maximum final score Mitsubachi can obtain?
Input
$N$
$p_1 \ \ a_1$
$p_2 \ \ a_2$
$\ \vdots$
$p_n \ \ a_n$
All inputs are integers.
$1 \leq N \leq 10^5$
$1 \leq p_i \leq 10^4$
$1 \leq a_i \leq p_i$
Output
Output the answer on $1$ line.
Print a newline at the end.
Sample
Sample 1
Input
2
3 2
4 2
Output
10
If he knocks down $2$ pins in turn $1$ and $4$ pins in turn $2$, the score of turn $1$ is $2+4=6$ and the score of turn $2$ is $4$, for a total of $10$ points, which is the maximum.
Sample 2
Input
2
1 1
1 1
Output
3
It is possible that $p_i = a_i$.
Source
Nada High School 75th Class Junior High Graduation Commemorative Contest: Strange Bowling
writer: karudano
tester: Mitarushi
Ported in accordance with the HackerRank terms of service. Some parts have been modified.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
蜜蜂