Q 1629: [Algorithm Training VIP]Water connection problems
Time limit: 1Sec Memory Limit: 128MB
Title Description
The school has a water room with a total of m faucets for students to turn on the water, each with an equal volume of water per second of 1.
Now there are n students ready to receive water, and their initial order of receiving water has been determined. The students are numbered from 1 to n in the order in which they receive water, and the amount of water received by student i is wi. At the beginning of the connection, students 1 to m each occupy a faucet and turn on the faucet at the same time to receive water. When one of the students, j, completes the required amount of water, the next student in line, k, immediately takes the place of j and starts to receive water. This changeover process is instantaneous and no water is wasted. That is, when student j finishes receiving water at the end of the xth second, student k immediately starts receiving water at the xth+1st second. If the current number of water connections n’ is less than m, then only n’ taps are supplied and the other m-n’ taps are closed.
Now, given the amount of water received by n students, ask how many seconds it takes for all students to finish receiving water according to the above rules.
Input
Row 1 has two integers n and m, separated by a space, indicating the number of persons receiving water and the number of faucets, respectively. Row 2 has n integers w1, w2, ……, wn, separated by a space between each integer, and wi represents the amount of water received by student i. 1 ≤ n ≤ 10000,1 ≤ m ≤ 100 且 m ≤ n; 1 ≤ wi ≤ 100。
Output
The output is a single line, 1 integer, indicating the total time required to pick up the water.
Sample Input
|
|
Sample Output
|
|
C Code
|
|