#P8211. [THUPC 2022 初赛] 搬砖
[THUPC 2022 初赛] 搬砖
Background
Zhang Hua got into Peking University; Li Ping entered a secondary technical school; Little E carries bricks on a construction site: they all have a bright future.
Problem Description
Friendly reminder: Please do not imitate Little E’s way of carrying bricks; it is very tiring.
To carry bricks happily, Little E has a special method.
Suppose there are stacks of bricks in front of him. Within one hour, he will carry away the top bricks from each stack. Here, is Little E’s current energy value. If a stack has fewer than bricks, Little E will carry away all remaining bricks in that stack.
After Little E finishes one hour of work, if he finds that he has emptied at least one stack of bricks, he will feel happy and continue working for another hour; however, since part of the work has been completed, Little E may become lazy, causing his energy value to decrease. Specifically, each stack has an attribute . When Little E empties that stack, his energy value decreases by .
If no stack is emptied, Little E will stop working. If his energy value drops to or below, Little E will also stop working. If Little E finds that he needs to work but all bricks have already been carried away, he will spend this hour doing something else, but this hour is still counted as Little E’s working time.
Bricks on the construction site keep being added. Given that Little E’s initial energy value is , how many consecutive hours can he work?
Input Format
The first line contains a positive integer , indicating the total number of events.
In the next lines, each line contains several integers, where the first integer is , indicating the event type.
If , it is followed by two integers , meaning a new stack of bricks is added. The stack has bricks, and after it is emptied, Little E’s energy value will decrease by .
If , it is followed by a positive integer , asking: if Little E’s initial energy value is , how many consecutive hours can he work?
Note that an operation will not change the number of bricks in any stack.
Output Format
For each query, output one line with one integer representing the answer.
5
1 6 1
1 3 0
1 9 2
2 3
2 4
3
4
4
1 2 1
2 2
1 2 1
2 2
2
1
Hint
[Sample Explanation]
First query:
Initially there are stacks of bricks, with quantities . Little E’s initial energy is .
In the first hour, Little E carries bricks from each stack, and the quantities become . The second stack is emptied, so Little E’s energy decreases by , and he continues working for another hour.
In the second hour, Little E carries bricks from each stack, and the quantities become . The first stack is emptied, so Little E’s energy decreases by , and he continues working for another hour.
In the third hour, Little E carries bricks from each stack, and the quantities become . Since no new stack is emptied, Little E stops working.
Second query:
Initially there are stacks of bricks, with quantities . Little E’s initial energy is .
In the first hour, Little E carries bricks from each stack (the second stack has only bricks so he carries only bricks; the same is omitted below), and the quantities become . The second stack is emptied, so Little E’s energy decreases by , and he continues working for another hour.
In the second hour, Little E carries bricks from each stack, and the quantities become . The first stack is emptied, so Little E’s energy decreases by , and he continues working for another hour.
In the third hour, Little E carries bricks from each stack, and the quantities become . The third stack is emptied, so Little E’s energy decreases by , and he continues working for another hour.
In the fourth hour, Little E carries brick from each stack, but in fact there are no bricks at this time. However, this hour is still counted as Little E’s working time. Since no new stack is emptied, Little E stops working.
[Sample Explanation 2]
First query:
Initially there is stack of bricks, with quantity . Little E’s initial energy is .
In the first hour, Little E carries bricks from the stack, and the quantity becomes . This stack is emptied, so Little E’s energy decreases by , and he continues working for another hour.
In the second hour, Little E carries brick from the stack, but in fact there are no bricks at this time. However, this hour is still counted as Little E’s working time. Since no new stack is emptied, Little E stops working.
Second query:
Initially there are stacks of bricks, with quantities . Little E’s initial energy is .
In the first hour, Little E carries bricks from each stack, and the quantities become . Both stacks are emptied, so Little E’s energy decreases by . Since Little E’s energy drops to , he stops working.
[Constraints]
It is guaranteed that $T\le 351493,1\le op\le 2,1\le a\le 100000,0\le b\le 100000,1\le d \le 100000$.
Translated by ChatGPT 5