/
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 366 点
問題文
高橋君は 1 日目から N 日目までの N 日間にわたるトレーニングの計画を立てています。
各日 i (1 \leq i \leq N) において、高橋君は以下の 2 つのメニューのうちいずれか一方を選んで行います。
- 通常トレーニングを行う。この場合、トレーニングの効果として A_i を得る。
- ハードトレーニングを行う。この場合、トレーニングの効果として B_i を得る。
ただし、体に過度な負担がかかるため、ハードトレーニングを 2 日連続で行うことはできません。すなわち、i 日目 (1 \leq i \leq N-1) にハードトレーニングを行った場合、i+1 日目にハードトレーニングを行うことはできません。
高橋君が N 日間のトレーニングメニューを適切に選んだとき、N 日間で得られる効果の合計として達成可能な最大値を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9
- 1 \leq B_i \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で与えられる。
N A_1 B_1 A_2 B_2 : A_N B_N
- 1 行目には、日数を表す整数 N が与えられる。
- 続く N 行のうち i 行目 (1 \leq i \leq N) には、i 日目に通常トレーニングを行った場合の効果を表す整数 A_i と、ハードトレーニングを行った場合の効果を表す整数 B_i が空白区切りで与えられる。
出力
得られる効果の合計の最大値を 1 行に出力してください。
入力例 1
3 3 5 2 8 4 6
出力例 1
15
入力例 2
4 10 15 20 10 5 30 10 25
出力例 2
75
入力例 3
8 100 200 150 180 300 100 200 500 120 130 400 600 250 800 300 350
出力例 3
2770
入力例 4
15 100000000 500000000 200000000 300000000 800000000 900000000 400000000 200000000 600000000 1000000000 700000000 750000000 300000000 800000000 500000000 600000000 900000000 950000000 150000000 400000000 600000000 650000000 850000000 900000000 200000000 700000000 450000000 500000000 1000000000 1000000000
出力例 4
9900000000
入力例 5
1 1 1000000000
出力例 5
1000000000
Score : 366 pts
Problem Statement
Takahashi is making a training plan spanning N days, from Day 1 to Day N.
On each day i (1 \leq i \leq N), Takahashi chooses and performs one of the following two routines:
- Perform regular training. In this case, he gains a training benefit of A_i.
- Perform hard training. In this case, he gains a training benefit of B_i.
However, because it puts excessive strain on his body, he cannot perform hard training on two consecutive days. That is, if he performs hard training on Day i (1 \leq i \leq N-1), he cannot perform hard training on Day i+1.
Find the maximum possible total benefit Takahashi can gain over the N days by choosing his training routines appropriately.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9
- 1 \leq B_i \leq 10^9
- All input values are integers.
Input
The input is given in the following format:
N A_1 B_1 A_2 B_2 : A_N B_N
- The first line contains an integer N, representing the number of days.
- The i-th of the following N lines (1 \leq i \leq N) contains two space-separated integers, A_i, representing the benefit of performing regular training on Day i, and B_i, representing the benefit of performing hard training on Day i.
Output
Print the maximum possible total benefit in a single line.
Sample Input 1
3 3 5 2 8 4 6
Sample Output 1
15
Sample Input 2
4 10 15 20 10 5 30 10 25
Sample Output 2
75
Sample Input 3
8 100 200 150 180 300 100 200 500 120 130 400 600 250 800 300 350
Sample Output 3
2770
Sample Input 4
15 100000000 500000000 200000000 300000000 800000000 900000000 400000000 200000000 600000000 1000000000 700000000 750000000 300000000 800000000 500000000 600000000 900000000 950000000 150000000 400000000 600000000 650000000 850000000 900000000 200000000 700000000 450000000 500000000 1000000000 1000000000
Sample Output 4
9900000000
Sample Input 5
1 1 1000000000
Sample Output 5
1000000000