AtCoder Beginner Contest 218
翻译中…
Problem Statement
翻译中…
There are $N$ lamps numbered $1$ through $N$ arranged in a row. You are going to light $R$ of them in red and $N-R$ in blue.
翻译中…
For each $i=1,\ldots,N-1$, a reward of $A_i$ is given if Lamp $i$ and Lamp $i+1$ light up in different colors.
翻译中…
Find the maximum total reward that can be obtained by efficiently deciding the colors of the lamps.
翻译中…
Constraints
翻译中…
$2 \leq N \leq 2\times 10^5$$1 \leq R \leq N-1$$1 \leq A_i \leq 10^9$- All values in input are integers.
翻译中…
Input
翻译中…
Input is given from Standard Input in the following format:
翻译中…
N R
A_1 A_2 \ldots A_{N-1}
翻译中…
Output
翻译中…
Print the answer.
翻译中…
样例
Input #1
6 2
3 1 4 1 5
Output #1
11
Lighting up Lamps $3, 5$ in red and Lamps $1, 2, 4, 6$ in blue yields a total reward of $A_2+A_3+A_4+A_5=11$.
You cannot get any more, so the answer is $11$.
Input #2
7 6
2 7 1 8 2 8
Output #2
10
Lighting up Lamps $1, 2, 3, 4, 5, 7$ in red and Lamp $6$ in blue yields a total reward of $A_5+A_6=10$.
Input #3
11 7
12345 678 90123 45678901 234567 89012 3456 78901 23456 7890
Output #3
46207983
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。