#P6568. [NOI Online #3 提高组] 水壶

[NOI Online #3 提高组] 水壶

Problem Description

There are nn water jugs with infinite capacity, numbered from 11 to nn. Initially, jug ii contains AiA_i units of water.

You can perform at most kk operations. In each operation, you need to choose an index xx such that 1xn11 \le x \le n-1, and then pour all the water from jug xx into jug x+1x+1.

In the end, you may choose exactly one jug and drink all the water in it. Now, please find the maximum number of units of water you can drink.

Input Format

The first line contains a positive integer nn, indicating the number of water jugs.

The second line contains a non-negative integer kk, indicating the upper limit on the number of operations.

The third line contains nn non-negative integers, separated by spaces, representing the initial amounts of water A1A_1, A2A_2, \cdots, AnA_n.

Output Format

One line with a single non-negative integer, indicating the answer.

10
5
890 965 256 419 296 987 45 676 976 742

3813

Hint

Constraints

  • For 10%10\% of the testdata, it is guaranteed that n10n \le 10.
  • For 30%30\% of the testdata, it is guaranteed that n100n \le 100.
  • For 50%50\% of the testdata, it is guaranteed that n103n \le 10^3.
  • For 70%70\% of the testdata, it is guaranteed that n105n \le 10^5.
  • For 100%100\% of the testdata, it is guaranteed that 1n1061 \le n \le 10^6, 0kn10 \le k \le n-1, and 0Ai1030 \le A_i \le 10^3.

Translated by ChatGPT 5