#P15796. 【MX-J28-T3】「Cfz Round 8」Juice Problem
【MX-J28-T3】「Cfz Round 8」Juice Problem
Problem Description
There are cups in front of Yuki, numbered from to . For cups to , both the capacity and the current amount of juice are fixed: cup has capacity and currently contains units of juice. Cup has capacity , and the amount of juice in it is not fixed.
Yuki defines operation as pouring the juice in cup into cup . If at this time the amount of juice in cup exceeds its capacity, the juice will overflow until the amount of juice in the cup becomes equal to its capacity.
Now Yuki has queries. The -th query gives two parameters . You need to find: if cup contains units of juice, then after Yuki performs operations in order, how much juice will be in cup .
Note that these operations are not actually performed, meaning the queries are independent of each other.
Input Format
This problem contains multiple test cases.
The first line contains two non-negative integers , representing the test point ID and the number of test cases. means this test point is the sample.
Then each test case is given as follows:
- The first line contains two non-negative integers .
- The next lines: the -th line contains two non-negative integers .
- The next lines: the -th line contains two non-negative integers .
Output Format
For each test case:
- Output lines. The -th line contains one integer, the answer to the -th query.
0 1
3 3
4 0
9 8
13 8
5 1
0 2
3 3
4
8
13
0 2
5 3
3 1
6 2
9 3
7 2
8 0
4 3
0 4
1 5
2 1
0 0
3 1
5 2
8
7
7
1
Hint
Sample 1 Explanation
This sample contains test case.
For the st query:
- Cup contains units of juice. After pouring it into cup , since cup has capacity and , the juice overflows. Therefore, cup finally contains units of juice.
For the nd query:
- After operation , cup contains units of juice.
- After operation , cup contains units of juice.
For the rd query:
- After operation , cup contains units of juice.
- After operation , cup contains units of juice.
- After operation , cup contains units of juice.
Constraints
For all testdata:
- .
- , .
- For all , .
- For all , , .
::cute-table{tuack}
| Test Point ID | Special Property | |
|---|---|---|
| None | ||
| AC | ||
| ^ | A | |
| BC | ||
| B | ||
| C | ||
| None |
- Special Property A: for all , .
- Special Property B: for all , .
- Special Property C: for all , .
Translated by ChatGPT 5