atcoder#ABC258E. [ABC258E] Packing Potatoes
[ABC258E] Packing Potatoes
Score : points
Problem Statement
potatoes are coming from a conveyor belt one by one. The weights of the potatoes are described by a sequence of length : the weight of the -th potato coming is , where denotes the remainder when is divided by .
Takahashi will prepare an empty box and then pack the potatoes in order, as follows.
- Pack the incoming potato into the box. If the total weight of the potatoes in the box is now or greater, seal that box and prepare a new empty box.
You are given queries. In the -th query , given a positive integer , find the number of potatoes in the -th box to be sealed. It can be proved that, under the Constraints of the problem, there will be at least sealed boxes.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the answer to the -th query.
3 2 5
3 4 1
1
2
2
3
Before sealing the -nd box, Takahashi will do the following:
- Prepare an empty box.
- Pack the -st potato into the box. Now, the total weight of potatoes in the box is .
- Pack the -nd potato into the box. Now, the total weight of potatoes in the box is , which is not less than , so seal this box.
- Prepare a new empty box.
- Pack the -rd potato into the box. Now, the total weight of potatoes in the box is .
- Pack the -th potato into the box. Now, the total weight of potatoes in the box is .
- Pack the -th potato into the box. Now, the total weight of potatoes in the box is , which is not less than , so seal this box.
The -st box sealed contains potatoes, and the -nd box sealed contains potatoes.
10 5 20
5 8 5 9 8 7 4 4 8 2
1
1000
1000000
1000000000
1000000000000
4
5
5
5
5