There are \(N\) students in the class where each of them has two parameters, marks and the bound. There are two arrays \(M\) and \(B\) denoting the marks and the bound of \(N\) students in the class. Initially, the cutoff is zero for passing. Now, each of the students will be evaluated on the basis of his marks.
If the marks obtained by the student are greater than the cutoff, he or she will pass and the cutoff will be incremented by the bound of that student.
Your task is to find the maximum number of students that can pass if the arrangement of students is done properly.
Input format
- The first line contains an integer denoting the number of test cases \(T\).
- The first line of each test case contains an integer \(N\) denoting the number of students in the class.
- Next \(N\) lines of each test case contain two space-separated integers marks (Mi) and bound (Bi) of the ith student.
Output format
Print \(T\) lines. For each test case:
- Print a single line indicating the maximum number of students that can pass.
Constraints
\(1 \leq T \leq 200\)
\(1 \leq N \leq 2000\)
\(1 \leq M_i,Bi \leq 10^9 \forall i \in [1,N]\)
The sum of \(N\) over all test cases does not exceed 2000.
1 5 1 3 2 1 4 7 3 5 7 1
3
Order should be [2,1,3,4,5], initially cutoff is zero.
Second student has more marks than cutoff, he will pass and cutoff will now be one as bound for second student is 1.
First student has marks equal to cutoff, he will also pass and cutoff will be 1+3=4.
Third student has marks equal to cutoff , he will also pass and cutoff will be 4+7=11.
Now fourth and fifth students will fail because both of them have marks less than 11.
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor