|
Time |
Memory |
| Case 1 |
1 sec |
32 MB |
| Case 2 |
1 sec |
32 MB |
| Case 3 |
1 sec |
32 MB |
| Case 4 |
2 sec |
32 MB |
Description
Ben is hurrying for the restroom!
As you might know, men have a habit when choosing which urinal (小便斗) to use: choose the one from other people as far as possible.
Let's define this habit more formally.
- Considering the i-th urinal (index increases from left to right), define Li and Ri as
- Li: the number of urinals between the rightmost people in the left of the i-th urinal and the i-th urinal;
- Ri: the number of urinals between the leftmost people in the right of the i-th urinal and the i-th urinal.

- By the way, there are always 2 security guards in the leftmost and rightmost of the restroom (not occupying any urinal) for some unknown security reason. They will also be treated as people mentioned in the above definition when determining distances.

- When Ben arrives at the restroom, he will pick the i-th urinal such that min(Li, Ri) is the maximum among all available urinals. If there exist multiple available choices, then he will pick the one with the smallest i (the leftmost one).
Let's give an example to demonstrate how everything's going:
G0001000G (status of occupation: 1 means occupied, 0 means available, G means security guard)
-1234567- (index of urinal)
| i |
Li |
Ri |
| 1 |
0 |
2 |
| 2 |
1 |
1 |
| 3 |
2 |
0 |
| 4 |
- |
- |
| 5 |
0 |
2 |
| 6 |
1 |
1 |
| 7 |
2 |
0 |
So for the man who just arrives at the restroom, he will choose the 2nd urinal, making the status become
G0101000G
And now the question is:
If Ben is the k-th man arriving at the restroom and suppose no one ever leaves his urinal, which urinal will Ben choose?
Input
Input consists of multiple testcases. There is an integer T in the first line, indicating there are T testcases.
Each testcase consists of 1 line, containing 2 integers N and K, where N is the total number of urinals, and K means Ben is the K-th man arriving at the restroom.
It is guaranteed that
Hint
1. No recursion. Loop is enough!
2. Testcase
- Testcase1: T = 1, K = 1
- Testcase2: T <= 10, K = 1
Output
For each testcase, print out the index of the urinal that Ben will choose.
(Index starts from 1, and increases from left to right.)
Tags