/
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
高橋君は 1 日目から N 日目までの N 日間の休暇を過ごします。
高橋君はこの休暇の中から、ちょうど K 日を選んで外出することにしました。
ただし、体力を維持するため、連続する 2 日間(1 \le i \le N - 1 を満たす任意の整数 i についての i 日目と i + 1 日目)の両方に外出することはできません。
i 日目 (1 \le i \le N) に外出すると、満足度 A_i が得られます。
高橋君が条件を満たすように外出する日を選んだとき、得られる満足度の合計の最大値を求めてください。
なお、本問題の制約下において、条件を満たす外出日の選び方が少なくとも 1 つ存在することが保証されています。
制約
- 1 \le N \le 5000
- 1 \le K \le \lceil N / 2 \rceil(\lceil x \rceil は x 以上の最小の整数を表す)
- 1 \le A_i \le 10^9
- 入力はすべて整数
入力
入力は以下の形式で与えられる。
N K A_1 A_2 \vdots A_N
出力
高橋君が得られる満足度の合計の最大値を 1 行で出力してください。
入力例 1
5 2 3 5 2 4 1
出力例 1
9
入力例 2
4 2 10 5 8 10
出力例 2
20
入力例 3
10 4 1000000000 500000000 800000000 200000000 900000000 100000000 700000000 300000000 600000000 400000000
出力例 3
3400000000
入力例 4
20 7 84 32 95 42 12 67 91 23 58 74 39 88 50 61 99 17 45 78 83 29
出力例 4
614
入力例 5
1 1 1000000000
出力例 5
1000000000
Score : 400 pts
Problem Statement
Takahashi will spend a vacation of N days, from Day 1 to Day N.
He has decided to choose exactly K days during this vacation to go out.
However, to maintain his stamina, he cannot go out on two consecutive days (both Day i and Day i + 1 for any integer i satisfying 1 \le i \le N - 1).
If he goes out on Day i (1 \le i \le N), he gains a satisfaction of A_i.
Find the maximum possible total satisfaction Takahashi can obtain by choosing the days to go out such that the condition is satisfied.
Under the constraints of this problem, it is guaranteed that there is at least one valid way to choose the days.
Constraints
- 1 \le N \le 5000
- 1 \le K \le \lceil N / 2 \rceil (\lceil x \rceil represents the smallest integer greater than or equal to x)
- 1 \le A_i \le 10^9
- All input values are integers.
Input
The input is given in the following format:
N K A_1 A_2 \vdots A_N
Output
Print the maximum total satisfaction Takahashi can obtain in a single line.
Sample Input 1
5 2 3 5 2 4 1
Sample Output 1
9
Sample Input 2
4 2 10 5 8 10
Sample Output 2
20
Sample Input 3
10 4 1000000000 500000000 800000000 200000000 900000000 100000000 700000000 300000000 600000000 400000000
Sample Output 3
3400000000
Sample Input 4
20 7 84 32 95 42 12 67 91 23 58 74 39 88 50 61 99 17 45 78 83 29
Sample Output 4
614
Sample Input 5
1 1 1000000000
Sample Output 5
1000000000