#K50092. Minimum Hours to Transfer Cooking Skills
Minimum Hours to Transfer Cooking Skills
Minimum Hours to Transfer Cooking Skills
Alice is organizing a cooking workshop with n participants arranged in a row (numbered from 1 to n). Initially, all participants have zero cooking skills except for Alice, who possesses all the necessary skills. Alice stands at position k where 1 ≤ k ≤ n.
In each hour, a participant can either teach one unit of cooking skill to one of their immediate neighbors (left or right) or learn one unit from a neighbor. Note that at any given hour a participant cannot both teach and learn simultaneously. When a participant x is teaching, the neighbor y receiving the skill is concurrently learning from x.
Your task is to determine the minimum number of hours required so that every participant ends up with the cooking skills. It can be shown that the answer is determined by the farthest distance from Alice. In other words, if we let \(L = k - 1\) and \(R = n - k\), the answer is \(\max(L, R)\).
inputFormat
The first line of the input contains an integer T — the number of test cases.
Each of the following T lines contains two space-separated integers n and k, where n is the number of participants and k is Alice's position.
outputFormat
For each test case, output a single integer — the minimum number of hours required for all participants to have the cooking skills. Each result should be printed on a new line.
## sample4
4 1
5 3
1 1
10 10
3
2
0
9
</p>