#P2793. Facer的工厂
Facer的工厂
Description
Facer is a part-time worker in a factory, and this time he encounters a problem.
There are steel pipes, with the -th pipe having length .
There is a pipe processor that can process units of pipe length per second.
Facer needs to process these pipes in order.
The machine has a maximum waiting length , meaning the total length of pipes waiting to be processed (already fed into the machine but not yet processed) cannot exceed (guaranteed that ).
Facer can only feed pipes into the machine at integer seconds.
What is the minimum time for Facer to finish processing all the pipes?
Input Format
The first line contains , representing the number of pipes, the maximum waiting length, and the processing speed per second.
The next lines each contain one number, the length of a pipe.
The pipes must be processed in order.
Output Format
The minimum time.
1 5 3
5
2
5 6 3
5 4 3 2 1
5
Hint
Sample 1 explanation: There is only pipe, and the processing time is .
Sample 2 explanation:
- At the first second, feed , waiting length is . The machine processes , waiting length becomes .
- At the second second, feed , waiting length is . The machine processes , waiting length becomes .
- At the third second, feed , waiting length is . The machine processes , waiting length becomes .
- At the fourth second, feed , waiting length is . The machine processes , waiting length becomes .
- At the fifth second, feed nothing, waiting length is . The machine processes , and all pipes are finished.
Constraints: , .
Problem by zhouyonglong.
Translated by ChatGPT 5
京公网安备 11011102002149号