#t376. 接水问题
接水问题
Fetching Water
Background
Special for beginners, ^_^
Problem Description
There is a water room in the school. It is equipped with a total of taps for students to fetch water, and each tap supplies water at the same rate of unit per second.
Now there are students about to fetch water, and their initial order has already been fixed. The students are numbered from to in this order, and the amount of water that student needs to fetch is . When water fetching starts, students to each occupy one tap and turn on their taps simultaneously. When some student finishes fetching the required amount , the next waiting student immediately takes over student 's position and starts fetching water. This switch happens instantly, with no water wasted: if student finishes at the end of second , student starts immediately at second . If the current number of students fetching water, , is less than , only taps supply water and the other taps are turned off.
Given the amounts of the 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 and , separated by a space, denoting the number of students and the number of taps respectively.
The second line contains integers , separated by spaces, where is the amount of water needed by student .
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 -st second, people fetch water. At the end of the -st second, students have each fetched unit; student finishes, and student takes over student 's position.
In the -nd second, people fetch water. At the end of the -nd second, students have each fetched units, and student has fetched unit.
In the -rd second, people fetch water. At the end of the -rd second, students have each fetched units, and student has fetched units. Student finishes, and student takes over student 's position.
In the -th second, people fetch water. At the end of the -th second, students have each fetched units, and student has fetched unit. Students finish, meaning everyone has finished fetching water.
The total time needed to fetch water is seconds.
8 4
23 71 87 32 70 93 80 76
163
Constraints
1s, 1024KiB for each test case.