CF182C.Optimal Sum

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

And here goes another problem on arrays. You are given positive integer lenlen and array aa which consists of nn integers a1a_{1} , a2a_{2} , ..., ana_{n} . Let's introduce two characteristics for the given array.

  • Let's consider an arbitrary interval of the array with length lenlen , starting in position ii . Value , 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 lenlen , taken in its absolute value.
  • Value 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 lenlen .

Your task is to calculate the optimal sum of the given array aa . However, before you do the calculations, you are allowed to produce no more than kk consecutive operations of the following form with this array: one operation means taking an arbitrary number from array aia_{i} and multiply it by -1. In other words, no more than kk times you are allowed to take an arbitrary number aia_{i} from the array and replace it with ai-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 kk operations described above are completed.

输入格式

The first line contains two integers nn , lenlen ( 1<=len<=n<=1051<=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 nn integers a1a_{1} , a2a_{2} , ..., ana_{n} (ai<=109)(|a_{i}|<=10^{9}) — the original array.

The third line contains a single integer kk ( 0<=k<=n0<=k<=n ) — the maximum allowed number of operations.

All numbers in lines are separated by a single space.

输出格式

In a single line print the maximum possible optimal sum after no more than kk 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.

输入输出样例

  • 输入#1

    5 3
    0 -2 3 -5 1
    2
    

    输出#1

    10
    
  • 输入#2

    5 2
    1 -3 -10 4 1
    3
    

    输出#2

    14
    
  • 输入#3

    3 3
    -2 -5 4
    1
    

    输出#3

    11
    
首页