Choco Boxes

3.9

12 votes
Problem

In a room there are N empty boxes in a row indexed from 1 to N. At a time, 2 people enter the room each having a chocolate bar with him. The 1st person puts the chocolate inside the box which has the least number of chocolates moving from 1 to N. The 2nd person puts the chocolate inside the box which has the least number of chocolates moving from N to 1. Next 2 people enter the room when the earlier two people have left. Find the index of the box and the number of chocolates already kept inside that box for the Mth person.

Note: In case M is odd, the last person walks into the room alone and puts the chocolate inside the box containing least number of chocolates moving from 1 to N.

Input Format : The first line contains T, the number of test cases. Each test case consists of one line containing N, the number of boxes, and M, the person to enter the room, separated by space. Output Format: The index of the box inside which the Mth person puts the chocolate and number of chocolates already kept inside that box.

Constraints: 1≤T≤10 1≤N≤50000 1≤M≤10^6

Time Limit: 0
Memory Limit: 256
Source Limit:
Editor Image

?