Logo
(追記) (追記ここまで)

19283번 - Lunch Queue 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2.5 초 512 MB80171426.923%

문제

It is lunch time! That's why $n$ employees are coming to the canteen to have lunch. It is known that $i$-th employee works in the team $c_i$ and has impudence $a_i$.

Suppose there are currently $l$ people in the queue. Positions in the queue are numbered from 1ドル$ to $l$ 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 $k$ (1ドル \leq k \leq l + 1$), he shifts the $k$-th person and everybody behind him one position back and gets the position $k$. In particular, $k = 1$ corresponds to the beginning of the queue and $k = l + 1$ corresponds to the end of the queue.

An employee $i$ can stay at the position $k$ only if two conditions are held:

  • After getting to the position $k,ドル at least one of the neighbors of newcomer is from the same team $c_i$;
  • A newcomer is not shifting too much people for his level of impudence, namely: $k \geq l + 1 - a_i$.

Among all $k$ satisfying the conditions above the minimum possible is chosen. If there are no suitable values of $k,ドル 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_i$ and $a_i,ドル find out how the queue will look like in the end.

입력

The first line contains an integer $n$ (1ドル \le n \le 400,000円$), the number of employees.

Each of the next $n$ lines contains two integers $c_i,ドル $a_i$ (1ドル \le c_i \le n,ドル 0ドル \le a_i \le 400,000円$), the team and the impudence of the $i$-th employee.

출력

Output $n$ distinct integers from 1ドル$ to $n$ 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 1ドル$ to $n$ in order of their appearance in the input data.

제한

예제 입력 1

8
1 0
2 1
2 2
1 1
3 2
1 3
2 3
2 5

예제 출력 1

1 3 8 2 7 6 4 5 

힌트

출처

Camp > Petrozavodsk Programming Camp > Winter 2018 > Day 4: Yandex Cup 2018 D번

Contest > Open Cup > 2017/2018 Season > Stage 11: Grand Prix of Khamovniki D번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /