Codeforces Round 466 (Div. 2)
E
Cashback
Codeforces
2000
原题
← DF →
翻译中…

Since you are the best Wraith King, Nizhniy Magazin «Mir» at the centre of Vinnytsia is offering you a discount.

翻译中…

You are given an array $*a*$ of length $*n*$ and an integer $*c*$.

翻译中…

The value of some array $*b*$ of length $*k*$ is the sum of its elements except for the image smallest. For example, the value of the array $[3, 1, 6, 5, 2]$ with $*c* = 2$ is $3 + 6 + 5 = 14$.

翻译中…

Among all possible partitions of $*a*$ into contiguous subarrays output the smallest possible sum of the values of these subarrays.

翻译中…

Input

翻译中…

The first line contains integers $*n*$ and $*c*$ ($1 ≤ *n*, *c* ≤ 100 000$).

翻译中…

The second line contains $*n*$ integers $*a*_{*i*}$ ($1 ≤ *a*_{*i*} ≤ 10^{9}$) — elements of $*a*$.

翻译中…

Output

翻译中…

Output a single integer  — the smallest possible sum of values of these subarrays of some partition of $*a*$.

翻译中…

Note

翻译中…

In the first example any partition yields 6 as the sum.

翻译中…

In the second example one of the optimal partitions is $[1, 1], [10, 10, 10, 10, 10, 10, 9, 10, 10, 10]$ with the values 2 and 90 respectively.

翻译中…

In the third example one of the optimal partitions is $[2, 3], [6, 4, 5, 7], [1]$ with the values 3, 13 and 1 respectively.

翻译中…

In the fourth example one of the optimal partitions is $[1], [3, 4, 5, 5, 3, 4], [1]$ with the values 1, 21 and 1 respectively.

翻译中…

样例

Input #1
3 5
1 2 3
Output #1
6
InputCopy OutputCopy
Input #2
12 10
1 1 10 10 10 10 10 10 9 10 10 10
Output #2
92
InputCopy OutputCopy
Input #3
7 2
2 3 6 4 5 7 1
Output #3
17
InputCopy OutputCopy
Input #4
8 4
1 3 4 5 5 3 4 1
Output #4
23
InputCopy OutputCopy
题目信息
题号
940E
时间限制
2 s
内存限制
256 MB
标签
数据结构
动态规划
贪心
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。