CF38G.Queue

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

On a cold winter evening our hero Vasya stood in a railway queue to buy a ticket for Codeforces championship final. As it usually happens, the cashier said he was going to be away for 5 minutes and left for an hour. Then Vasya, not to get bored, started to analyze such a mechanism as a queue. The findings astonished Vasya.

Every man is characterized by two numbers: aia_{i} , which is the importance of his current task (the greater the number is, the more important the task is) and number cic_{i} , which is a picture of his conscience. Numbers aia_{i} form the permutation of numbers from 11 to nn .

Let the queue consist of n1n-1 people at the moment. Let's look at the way the person who came number nn behaves. First, he stands at the end of the queue and the does the following: if importance of the task aia_{i} of the man in front of him is less than ana_{n} , they swap their places (it looks like this: the man number nn asks the one before him: "Erm... Excuse me please but it's very important for me... could you please let me move up the queue?"), then he again poses the question to the man in front of him and so on. But in case when aia_{i} is greater than ana_{n} , moving up the queue stops. However, the man number nn can perform the operation no more than cnc_{n} times.

In our task let us suppose that by the moment when the man number nn joins the queue, the process of swaps between n1n-1 will have stopped. If the swap is possible it necessarily takes place.

Your task is to help Vasya model the described process and find the order in which the people will stand in queue when all the swaps stops.

输入格式

The first input line contains an integer nn which is the number of people who has joined the queue ( 1<=n<=1051<=n<=10^{5} ). In the next nn lines descriptions of the people are given in order of their coming — space-separated integers aia_{i} and cic_{i} ( 1<=ai<=n1<=a_{i}<=n , 0<=ci<=n0<=c_{i}<=n ). Every description is located on s single line. All the aia_{i} 's are different.

输出格式

Output the permutation of numbers from 11 to nn , which signifies the queue formed according to the above described rules, starting from the beginning to the end. In this succession the ii -th number stands for the number of a person who will stand in line on the place number ii after the swaps ends. People are numbered starting with 11 in the order in which they were given in the input. Separate numbers by a space.

输入输出样例

  • 输入#1

    2
    1 0
    2 1
    

    输出#1

    2 1 
  • 输入#2

    3
    1 3
    2 3
    3 3
    

    输出#2

    3 2 1 
  • 输入#3

    5
    2 3
    1 4
    4 3
    3 1
    5 2
    

    输出#3

    3 1 5 4 2 
首页