Codeforces Round 980 (Div. 2)
A
Profitable Interest Rate
Codeforces
800
原题
←B →
翻译中…

Alice has $a$ coins. She can open a bank deposit called "Profitable", but the minimum amount required to open this deposit is $b$ coins.

翻译中…

There is also a deposit called "Unprofitable", which can be opened with any amount of coins. Alice noticed that if she opens the "Unprofitable" deposit with $x$ coins, the minimum amount required to open the "Profitable" deposit decreases by $2x$ coins. However, these coins cannot later be deposited into the "Profitable" deposit.

翻译中…

Help Alice determine the maximum number of coins she can deposit into the "Profitable" deposit if she first deposits some amount of coins (possibly $0$) into the "Unprofitable" deposit. If Alice can never open the "Profitable" deposit, output $0$.

翻译中…

Input

翻译中…

Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The description of the test cases follows.

翻译中…

A single line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$) — the number of coins Alice has and the initial minimum amount required to open the "Profitable" deposit.

翻译中…

Output

翻译中…

For each test case, output a single integer — the maximum number of coins that Alice can deposit into the "Profitable" deposit. If Alice can never open the "Profitable" deposit, output $0$.

翻译中…

Note

翻译中…

In the first test case, $a \ge b$, so Alice can immediately open the "Profitable" deposit with all $10$ coins.

翻译中…

In the second test case, Alice can open the "Unprofitable" deposit with $2$ coins. Then she will have $5$ coins left, but the minimum amount required to open the "Profitable" deposit will decrease by $4$ coins, making it equal to $5$ coins. Thus, Alice will be able to open the "Profitable" deposit with $5$ coins.

翻译中…

In the third test case, Alice will not be able to open the "Profitable" deposit.

翻译中…

样例

Input #1
5
10 5
7 9
5 100
1 1
1 2
Output #1
10
5
0
1
0
InputCopy OutputCopy
题目信息
题号
2024A
时间限制
1 s
内存限制
256 MB
标签
贪心
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。