#t376. 接水问题

接水问题

Fetching Water

Background

Special for beginners, ^_^

Problem Description

There is a water room in the school. It is equipped with a total of mm taps for students to fetch water, and each tap supplies water at the same rate of 11 unit per second.

Now there are nn students about to fetch water, and their initial order has already been fixed. The students are numbered from 11 to nn in this order, and the amount of water that student ii needs to fetch is wiw_i. When water fetching starts, students 11 to mm each occupy one tap and turn on their taps simultaneously. When some student jj finishes fetching the required amount wjw_j, the next waiting student kk immediately takes over student jj's position and starts fetching water. This switch happens instantly, with no water wasted: if student jj finishes at the end of second xx, student kk starts immediately at second x+1x+1. If the current number of students fetching water, n′n', is less than mm, only n′n' taps supply water and the other m−n′m-n' taps are turned off.

Given the amounts wiw_i of the nn students, according to the rules above, find how many seconds are needed for all students to finish fetching water.

Input Format

The first line contains two integers nn and mm, separated by a space, denoting the number of students and the number of taps respectively.

The second line contains nn integers w1,w2,…,wnw_1, w_2, \dots, w_n, separated by spaces, where wiw_i is the amount of water needed by student ii.

Output Format

Output a single line with one integer: the total time needed to fetch water.

Sample Input 1

5 3
4 4 1 2 1

Sample Output 1

4

Hint

In the 11-st second, 33 people fetch water. At the end of the 11-st second, students 1,2,31, 2, 3 have each fetched 11 unit; student 33 finishes, and student 44 takes over student 33's position.

In the 22-nd second, 33 people fetch water. At the end of the 22-nd second, students 1,21, 2 have each fetched 22 units, and student 44 has fetched 11 unit.

In the 33-rd second, 33 people fetch water. At the end of the 33-rd second, students 1,21, 2 have each fetched 33 units, and student 44 has fetched 22 units. Student 44 finishes, and student 55 takes over student 44's position.

In the 44-th second, 33 people fetch water. At the end of the 44-th second, students 1,21, 2 have each fetched 44 units, and student 55 has fetched 11 unit. Students 1,2,51, 2, 5 finish, meaning everyone has finished fetching water.

The total time needed to fetch water is 44 seconds.

8 4
23 71 87 32 70 93 80 76
163

Constraints

1s, 1024KiB for each test case.