Codeforces Round 117 (Div. 2)
C
Optimal Sum
Codeforces
2000
原题
← BD →
翻译中…

And here goes another problem on arrays. You are given positive integer $*len*$ and array $*a*$ which consists of $*n*$ integers $*a*_{1}$, $*a*_{2}$, ..., $*a*_{*n*}$. Let's introduce two characteristics for the given array.

翻译中…
  • Let's consider an arbitrary interval of the array with length $*len*$, starting in position $*i*$. Value image, is the modular sum on the chosen interval. In other words, the modular sum is the sum of integers on the chosen interval with length $*len*$, taken in its absolute value.
  • Value image is the optimal sum of the array. In other words, the optimal sum of an array is the maximum of all modular sums on various intervals of array with length $*len*$.
翻译中…

Your task is to calculate the optimal sum of the given array $*a*$. However, before you do the calculations, you are allowed to produce no more than $*k*$ consecutive operations of the following form with this array: one operation means taking an arbitrary number from array $*a*_{*i*}$ and multiply it by -1. In other words, no more than $*k*$ times you are allowed to take an arbitrary number $*a*_{*i*}$ from the array and replace it with $- *a*_{*i*}$. Each number of the array is allowed to choose an arbitrary number of times.

翻译中…

Your task is to calculate the maximum possible optimal sum of the array after at most $*k*$ operations described above are completed.

翻译中…

Input

翻译中…

The first line contains two integers $*n*$, $*len*$ ($1 ≤ *len* ≤ *n* ≤ 10^{5}$) — the number of elements in the array and the length of the chosen subinterval of the array, correspondingly.

翻译中…

The second line contains a sequence consisting of $*n*$ integers $*a*_{1}$, $*a*_{2}$, ..., $*a*_{*n*}$ $(|*a*_{*i*}| ≤ 10^{9})$ — the original array.

翻译中…

The third line contains a single integer $*k*$ ($0 ≤ *k* ≤ *n*$) — the maximum allowed number of operations.

翻译中…

All numbers in lines are separated by a single space.

翻译中…

Output

翻译中…

In a single line print the maximum possible optimal sum after no more than $*k*$ acceptable operations are fulfilled.

翻译中…

Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

翻译中…

样例

Input #1
5 3
0 -2 3 -5 1
2
Output #1
10
InputCopy OutputCopy
Input #2
5 2
1 -3 -10 4 1
3
Output #2
14
InputCopy OutputCopy
Input #3
3 3
-2 -5 4
1
Output #3
11
InputCopy OutputCopy
题目信息
题号
182C
时间限制
2 s
内存限制
256 MB
标签
数据结构
贪心

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