| SanSi Cup 2026 Qualification round |
|---|
| Finished |
Mateo uses Claude for everything, even for programming. One night he dreams that he is back at university and wakes up in the middle of the second midterm of Low-Level Programming, the course that scared him the most. He reads the statement and tries to ask Claude, but back then Claude did not exist. A true nightmare!
In the first midterm Mateo got $$$X$$$. Exam grades are integers between $$$0$$$ and $$$Z$$$, inclusive. If he gets $$$N$$$ in the second midterm, his average is $$$\dfrac{X + N}{2}$$$, without rounding, and he passes the course if that average is at least $$$W$$$.
Mateo does not want to compute it by hand, so this time you will be his Claude: tell him the minimum grade $$$N$$$ he needs in the second midterm to pass.
The first line contains an integer $$$t$$$, the number of test cases.
Each of the following $$$t$$$ lines contains three integers $$$X$$$, $$$W$$$ and $$$Z$$$: the grade of the first midterm, the minimum average to pass and the maximum grade of an exam.
Constraints
For each case, print on one line the minimum grade $$$N$$$, with $$$0 \le N \le Z$$$, that lets Mateo pass. If he cannot pass even by getting $$$Z$$$, print $$$-1$$$.
4 40 51 100 80 30 100 10 60 100 0 50 100
62 0 -1 100
3 7 5 10 0 1 1 1 1 1
3 -1 1
Example 1. In the first case, with $$$62$$$ the average is $$$\frac{40 + 62}{2} = 51$$$, and with $$$61$$$ it would be $$$50.5$$$. In the second, Mateo already passes even if he gets $$$0$$$, because $$$\frac{80 + 0}{2} = 40$$$. In the third, even with $$$100$$$ the average is $$$55$$$, less than $$$60$$$. In the fourth, he needs exactly the maximum grade.
Example 2. In the first case, with $$$3$$$ the average is $$$\frac{7 + 3}{2} = 5$$$. In the second, the highest possible average is $$$\frac{0 + 1}{2} = 0.5$$$, less than $$$1$$$. In the third, with $$$1$$$ the average is $$$1$$$.
| Name |
|---|


