Scheduling

시간 제한3초메모리 제한2048 MB

요약
각 회의를 주어진 구간 안의 한 시간 슬롯에 배정하되, 어떤 두 회의 사이에도 최소 한 시간의 공백이 생기도록 하고, 불가능하면 -1을 출력한다.
난이도

보통10점 중 7점

유형
그리디, 정렬, 구간
정답자
아직 제출이 없습니다

문제

Your boss made you find a valid schedule for his meetings. He has nn meetings, where the ii-th meeting has to start and end in the time interval \[ℓ_i,r_i]\[\ell\_i, r\_i], where time is measured in hours. Each meeting takes exactly one hour, and your boss obviously cannot attend two meetings at the same time.

As a competitive programmer, you have already solved this classical scheduling problem countless times, and this time, you finally notice that it is completely unrealistic. How can one person attend over a hundred thousand meetings at different places without any time to travel between them and without taking any breaks either? There is no way every meeting takes exactly one hour -- speaking from experience -- and there will surely be meetings that start late because someone is running late.

These deep-rooted philosophical questions may be a big problem for humanity, but since you do not have to attend these meetings yourself, you simply do not care enough to solve all of them. However, impressing your boss will certainly be worth it for you, so you try to at least improve the schedule a little bit.

Find any schedule where there is at least one hour between every pair of meetings or report that there is none. Surely this is just one insignificant change to the classical problem, right?

입력

Each test contains multiple test cases. The first line of input contains a single integer tt (1≤t≤1051 \leq t \leq 10^5) --- the number of test cases. The description of the test cases follows.

The first line of each test case contains one integer nn (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5) --- the number of meetings.

The next nn lines each contain two integers ℓ_i\ell\_i and r_ir\_i (1≤ℓ_i<r_i≤1061 \leq \ell\_i < r\_i \leq 10^6) --- the time interval in hours the ii-th meeting has to start and end in.

The sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

출력

If there is no valid schedule, output −1-1 in a single line. Otherwise, output nn integers a_ia\_i in a single line where a_ia\_i is the start time of the ii-th meeting.

힌트

In the first test case, the first meeting starts at the start of hour 11 and goes on for one hour until the start of hour 22. After that, your boss takes a break of one hour until he attends the third meeting from the start of hour 33 to 44. Then, he takes another one hour break until he finally attends the second meeting, which happens from the start of hour 55 to 66.

Note that it is not possible to start the third meeting at the start of hour 44 as this meeting would end at 55.

예제1

  1. 예제 1

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