아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Lunch Queue

시간 제한2.5초메모리 제한512 MB

요약
직원들이 한 명씩 도착해 같은 팀 동료 옆이면서 임피던스 범위 안에 드는 가장 앞자리에 들어갈 때, 최종 대기열 순서를 구한다.
난이도

보통10점 중 7점

유형
시뮬레이션, 연결 리스트, 구현, 그리디
정답자
아직 제출이 없습니다

문제

It is lunch time! That's why nn employees are coming to the canteen to have lunch. It is known that ii-th employee works in the team c_ic\_i and has impudence a_ia\_i. 

Suppose there are currently ll people in the queue. Positions in the queue are numbered from 11 to ll from the beginning of the queue. When a person comes to the canteen, he tries to get as close to the beginning of the queue as possible by staying next to one of his teammates. Formally, if a newcomer gets into the queue at the position kk (1≤k≤l+11 \leq k \leq l + 1), he shifts the kk-th person and everybody behind him one position back and gets the position kk. In particular, k=1k = 1 corresponds to the beginning of the queue and k=l+1k = l + 1 corresponds to the end of the queue.   

An employee ii can stay at the position kk only if two conditions are held:

  • After getting to the position kk, at least one of the neighbors of newcomer is from the same team c_ic\_i;
  • A newcomer is not shifting too much people for his level of impudence, namely: k≥l+1−a_ik \geq l + 1 - a\_i.

Among all kk satisfying the conditions above the minimum possible is chosen. If there are no suitable values of kk, a newcomer simply takes place after the last person in the queue.

For example, if there are five people in the queue working in teams 1, 3, 4, 1, 3 respectively (starting from the beginning of the queue) and the newcomer works in team 1 and has impudence 3, he stays at the position 4 of the queue. After that, the sequence of the employee teams becomes 1, 3, 4, 1, 1, 3. Note that impudence value of 3 also allowed him to get to the position 3, but there would be no teammates next to him in that case, so the first condition is violated.

Knowing the order in which employees arrive and their values of c_ic\_i and a_ia\_i, find out how the queue will look like in the end.

입력

The first line contains an integer nn (1≤n≤400,0001 \le n \le 400\\,000), the number of employees.

Each of the next nn lines contains two integers c_ic\_i, a_ia\_i (1≤c_i≤n1 \le c\_i \le n, 0≤a_i≤400,0000 \le a\_i \le 400\\,000), the team and the impudence of the ii-th employee.

출력

Output nn distinct integers from 11 to nn which are the indices of people in the queue from beginning of the queue to the end after all employees get to the canteen. Employees are indexed from 11 to nn in order of their appearance in the input data.

예제1

  1. 예제 1

    입력
    8
    1 0
    2 1
    2 2
    1 1
    3 2
    1 3
    2 3
    2 5
    
    예상 출력
    1 3 8 2 7 6 4 5