#P10924. Happybob's Game (UBC001D)
Happybob's Game (UBC001D)
Problem Description
Note: In this problem, all are assumed to satisfy and .
Happybob's game character is fighting a war.
He has armies. The -th army has soldiers and a consumption value , meaning that every minute, the number of soldiers in the -th army becomes . Once the number of soldiers in any army becomes , Happybob loses. Let the beginning be minute . Define the survival time as the minute right before one of Happybob's armies becomes . You may refer to the sample explanation.
However, Happybob is not willing to be wiped out like this. He comes up with a good idea: at any time that is not an integer minute, he can transfer some soldiers from one army to another. Formally, choose two armies and a transfer amount satisfying , and change into respectively. Note that between two integer minutes, he can perform transfers any number of times.
Happybob finds that this can effectively increase the armies' survival time. Now, as Happybob's most trusted chief of staff, you need to help him deploy troops.
Next, you are given operations. Each operation is one of the following:
- Operation , in the form
1 i x, means the number of soldiers of Happybob's -th army becomes (). - Operation , in the form
2 i x, means the consumption value of Happybob's -th army becomes (). - Operation , in the form
3, means you should output the maximum survival time that Happybob can theoretically achieve using the troop-transfer method above. Note that this operation does not change the values of or .
Input Format
The first line contains two positive integers .
The next two lines each contain positive integers, representing the array and the array .
The next lines each describe one of the three operations above.
Output Format
Suppose there are operations of type . Then your output should contain lines, each line giving the maximum possible survival time under the current state. If Happybob's armies can survive forever, output -1.
2 10
29 5
7 2
1 2 3
2 1 3
3
1 1 1
1 2 1
2 1 1
2 2 1
3
2 1 2
3
3
-1
0
Hint
Sample Explanation
For the first operation , Happybob can move troops like this:
| Time (min) | Soldiers in the first army | Soldiers in the second army |
|---|---|---|
Constraints
For of the testdata, , . It is guaranteed that for all , , .
Translated by ChatGPT 5