Job Completion

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

요약
각 작업에 시작 기한 s_i와 소요 시간 t_i가 주어질 때, 시간 0에서 한 번에 하나씩 처리해 완료할 수 있는 최대 작업 수를 구한다.
난이도

보통10점 중 7점

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

문제

Bessie the cow has NN (1≤N≤2⋅1051\le N\le 2\cdot 10^5) jobs for you to potentially complete. The ii-th one, if you choose to complete it, must be started at or before time s_is\_i and takes t_it\_i time to complete (0≤s_i≤1018,1≤t_i≤10180\le s\_i\le 10^{18}, 1\le t\_i\le 10^{18}).

What is the maximum number of jobs you can complete? Time starts at 00, and once you start a job you must work on it until it is complete, without starting any other jobs in the meantime.

입력

The first line contains TT, the number of independent test cases (1≤T≤101\le T\le 10). Each test case is formatted as follows.

The first line contains NN.

Each of the next NN lines contains two integers s_is\_i and t_it\_i. Row i+1i+1 has the details for the iith job.

It is guaranteed that the sum of NN over all test cases does not exceed 3⋅1053\cdot 10^5.

출력

For each test case, the maximum number of jobs you can complete, on a new line.

힌트

For the first test case, you can only complete one of the jobs. After completing one job, it will then be time 22 or later, so it is too late to start the other job, which must be started at time 11 or earlier.

For the second test case, you can start the second job at time 00 and finish at time 22, then start the first job at time 22 and finish at time 55.

예제1

  1. 예제 1

    입력
    3
    2
    1 4
    1 2
    2
    2 3
    1 2
    3
    1 4
    2 3
    1 2
    
    예상 출력
    1
    2
    2