Subarray-D

Time limit: 0.2s Memory limit: 256MB Input: Output:

Andrei and Alex are playing a game with an array VV of NN elements. Andrei can perform at most KK operations on the array. In each operation, he can decrease any element of the array by 1.

After performing these operations, Andrei must pay Alex SS dollars, where SS is the maximum subarray^* sum of the modified array. The subarray must contain at least one element. Since Andrei wants to pay as little as possible, he chooses his operations optimally to minimize SS.

^* An array bb is a subarray of an array aa if bb can be obtained from aa by deletion of several (possibly, zero) elements from the beginning and several (possibly, zero) elements from the end. In particular, an array is a subarray of itself.

Task

Given NN, KK and the array VV, what is the minimum amount of money Andrei will have to pay Alex?

Input data

The first line contains two integers, NN and KK. The second line contains NN integers ViV_i.

Output data

You need to write a single line with an integer: the value SS.

Constraints and clarifications

  • 1N200 0001 \le N \le 200 \ 000.
  • 0K1090 \le K \le 10^9.
  • 109Vi109-10^9 \le V_i \le 10^9 for each i=0N1i=0\ldots N-1.
# Score Constraints
1 0 Examples
2 6 K=0K = 0
3 14 K=1K = 1
4 6 0Vi1090 \le V_i \le 10^9 for each i=0N1i=0\ldots N-1.
4 16 50Vi50-50 \le V_i \le -50 for each i=0N1,K50i=0\ldots N-1, K \le 50.
5 58 No additional restrictions

Example 1

stdin

5 2
-1 2 3 -1 4

stdout

6

Explanation

In the first sample case, you can decrease the fifth element two times.

Example 2

stdin

6 7
-2 2 2 3 0 4

stdout

4

Explanation

In the second sample case, you can decrease the fourth element seven times.

Log in or sign up to be able to send submissions!