#BS0000487. Đóng hộp khoai tây (Packing Potatoes)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đóng hộp khoai tây (Packing Potatoes)
Packing Potatoes
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
A conveyor delivers potatoes to Takahashi in order. Their weights repeat the list : potato number weighs , where numbering starts at and denotes the remainder modulo .
Starting with an empty box, Takahashi places each arriving potato into it. As soon as the combined weight reaches or exceeds , he seals the box and starts another empty box. No potato may be skipped, and excess weight is not carried over to the next box.
For each of queries, report how many potatoes are in sealed box number . Boxes are numbered starting at in sealing order. The supply is sufficient to seal at least boxes for every query.
Input
- The first line contains integers : the length of the repeating weight list, the number of queries and the sealing threshold.
- The second line contains integers in cycle order.
- Each of the next lines contains an integer , identifying the box in query .
Output
Print lines. Line contains the number of potatoes in box .
Subtasks
- Subtask 1 (20 points): ; ; ; for all ; for all . All input values are integers; the supply suffices for every query.
- Subtask 2 (30 points): ; ; ; for all ; for all . All input values are integers; the supply suffices for every query.
- Subtask 3 (50 points): ; ; ; for all ; for all . All input values are integers; the supply suffices for every query.
Examples
Input 1
3 2 5
3 4 1
1
2
Output 1
2
3
Explanation 1
The sealing threshold is . The first box receives weights , with running totals , and contains potatoes. The next box receives weights , with running totals . It reaches the threshold only after its third potato, giving the second answer .
Input 2
10 5 20
5 8 5 9 8 7 4 4 8 2
1
1000
1000000
1000000000
1000000000000
Output 2
4
5
5
5
5
Explanation 2
The first box takes weights , totaling , so it contains potatoes. Beginning with box two, the starting indices in the weight list are (zero-based), then return to . Their potato counts are . All four large query indices are divisible by , corresponding to starting index , whose box contains potatoes.