#P2793. Facer的工厂

Facer的工厂

Description

Facer is a part-time worker in a factory, and this time he encounters a problem.

There are NN steel pipes, with the ii-th pipe having length aia_i.

There is a pipe processor that can process KK units of pipe length per second.

Facer needs to process these pipes in order.

The machine has a maximum waiting length HH, meaning the total length of pipes waiting to be processed (already fed into the machine but not yet processed) cannot exceed HH (guaranteed that aiHa_i \le H).

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 N,H,KN, H, K, representing the number of pipes, the maximum waiting length, and the processing speed per second.

The next NN 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 11 pipe, and the processing time is 5/3=2\lceil 5/3 \rceil = 2.

Sample 2 explanation:

  • At the first second, feed 55, waiting length is 55. The machine processes 33, waiting length becomes 22.
  • At the second second, feed 44, waiting length is 66. The machine processes 33, waiting length becomes 33.
  • At the third second, feed 33, waiting length is 66. The machine processes 33, waiting length becomes 33.
  • At the fourth second, feed 1,21, 2, waiting length is 66. The machine processes 33, waiting length becomes 33.
  • At the fifth second, feed nothing, waiting length is 33. The machine processes 33, and all pipes are finished.

Constraints: N100000N \le 100000, H,ai109H, a_i \le 10^9.

Problem by zhouyonglong.

Translated by ChatGPT 5