#P1190. [NOIP 2010 普及组] 接水问题
[NOIP 2010 普及组] 接水问题
Description
There is a water room in the school with a total of faucets that students can use. Each faucet supplies water at an equal rate of unit per second.
Now students are preparing to fetch water, and their initial order is fixed. Number the students from to according to this order, and let the required amount for student be . At the start, students through each occupy one faucet and start fetching water simultaneously. When some student finishes their required amount , the next student in the queue immediately takes ’s place and starts fetching water. This handover is instantaneous, and no water is wasted. Specifically, if student finishes at the end of second , then student starts at second . If the current number of students fetching water is , then only faucets supply water, and the remaining faucets are closed.
Given the required amounts for the students and following the rules above, determine how many seconds it takes for all students to finish fetching water.
Input Format
The first line contains two integers and , separated by a space, representing the number of students and the number of faucets.
The second line contains integers , separated by single spaces, where is the required amount for student .
Output Format
Output a single integer representing the total time required.
5 3
4 4 1 2 1
4
8 4
23 71 87 32 70 93 80 76
163
Hint
[Sample I/O #1 Explanation]
In the 1st second, 3 students are fetching water. At the end of the 1st second, students 1, 2, and 3 have each fetched 1 unit. Student 3 finishes, and student 4 takes student 3’s place to start fetching water.
In the 2nd second, 3 students are fetching water. At the end of the 2nd second, students 1 and 2 have each fetched 2 units, and student 4 has fetched 1 unit.
In the 3rd second, 3 students are fetching water. At the end of the 3rd second, students 1 and 2 have each fetched 3 units, and student 4 has fetched 2 units. Student 4 finishes, and student 5 takes student 4’s place to start fetching water.
In the 4th second, 3 students are fetching water. At the end of the 4th second, students 1 and 2 have each fetched 4 units, and student 5 has fetched 1 unit. Students 1, 2, and 5 finish, so the total time for everyone to finish is 4 seconds.
Constraints
, , ;
.
NOIP 2010 Junior Problem 2.
Translated by ChatGPT 5
京公网安备 11011102002149号