A bench in the subway has n places, marked with the numbers from 1 up to n. In the beginning the bench is empty – all the n places are vacant. In order, one by one, from the subway entry a person enters. He sits in the middle place of the first maximal continuous sequence of empty places. In case that maximal sequence of empty places contains an even number of places, the person sits in the place with the smaller number among the two middle places in this sequence. For example, if the bench has n = 6 places, the first person sits in place 3, because there is a unique sequence of empty places – from place 1 to 6, which contains an odd number of places, and 3 is the place with a smaller number among the two middle places (3 and 4) of this sequence. For the second person there are two sequences to choose from – from 1 to 2 and from 4 to 6. The sequence from 4 to 6 is maximal, containing 3 places, and the second person sits in its center – place 5.The third person sits in place 1 – the middle place for the sequence of places 1 to 2, the fourth person – in place 2, the fifth – in place 4 and the sixth – in place 6. Write a program bench, which finds the place in which a particular person sits, and given a place, which person sits on it. Input From the standard input you should read three natural numbers: n i p, with interval between them, where: • n is the total number of places of the bench, • i means the i-th person, and • p means the p-th place in the bench. Output Write to the standard output two numbers q and j, with an interval between them, for which it is true that: • i-th person sits in place q, and • j-th person sits in place p. Constraints 1 ≤ i, p ≤ n ≤ 1016 In 20% of the tests, n < 10000. In another 30% of the tests, n = 2k-1, where k>0 is an integer. Example: Input : 6 1 5 Output: 3 2 |
Short version: Let's say that I have 10 seats. I need to find the middle of this sequence of numbers (1-10). The middle seat is 5. Then I need to find the middle seat of the largest maximal continuous sequence. Right now I have two sequences. The first one is from 1 to 4 and the second one is from 6 to 10. Number 5 is already taken. I find that the largest sequence is from 6-10. And the middle seat is 8. I should do that until every seat is taken. |
|
|