#abc258e. E - Packing Potatoes
E - Packing Potatoes
Score : points
问题描述
个土豆将逐一从传送带上出来。土豆的重量由长度为 的序列 描述:第 个出来的土豆的重量是 ,其中 表示当 除以 后的余数。
高桥将会准备一个空箱子,并按照以下方式逐个打包土豆。
- 将传入的土豆装入箱子中。如果现在箱子里土豆的总重量达到或超过 ,则封住该箱子并准备一个新的空箱子。
给定 个查询。在第 个查询 中,给出一个正整数 ,求第 个被封住的箱子中的土豆数量。可以证明,在本问题的约束条件下,至少会有 个被封住的箱子。
以上为通义千问 qwen-max 翻译,仅供参考。
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.
Sample Input 1
3 2 5
3 4 1
1
2
Sample Output 1
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.
Sample Input 2
10 5 20
5 8 5 9 8 7 4 4 8 2
1
1000
1000000
1000000000
1000000000000
Sample Output 2
4
5
5
5
5
update @ 2024/3/10 10:57:58