시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 512 MB | 3 | 2 | 2 | 66.667% |
Master Zhu is watching a video. He wants to adjust the sound volume from $p$ dB to $q$ dB. Master Zhu is powerful enough to control the sound volume mentally. He needs one second to issue one order. So, each second, he may either issue an order "Up!", issue an order "Down!", or do nothing.
If he issues an order "Up!", the volume increases by $1$ dB. An order "Down!" works in a more compilcated way: if on the previous second, there was an order "Down!" and the volume decreased by $x$ dB, it decreases by $2 \cdot x$ dB, otherwise the volume decreases by $1$ dB.
If after some order the volume becomes negative, the system will break, so Master Zhu must be careful.
Find the minimum time needed for Master Zhu to adjust the volume from $p$ dB to $q$ dB.
The first line of input contains one integer $T$, the number of test cases ($1 \le T \le 3 \cdot 10^5$).
Each of the next $T$ lines contains two integers $p$ and $q$ ($0 \le p, q \le 10^9$).
For each test case, print a single line with a single integer: the minimum time in seconds Master Zhu needs to adjust the volume.
2 1 5 7 3
4 4