Alice’s Homework Challenge

Time limit: 0.4s Memory limit: 256MB Input: Output:

Alice has NN homework tasks, but she's already bored just thinking about them. To make it more exciting, she decides to set her own deadlines and rewards! She has MM seconds in total to complete the tasks.

For each i=0N1i=0 \ldots N-1, task ii takes SiS_i seconds to complete, and Alice has assigned a deadline of DiD_i seconds to it. She rewards herself with 22 points if she finishes the task before the deadline (including finishing it in the same second as the deadline), or 11 point if she finishes it after the deadline, but still within MM seconds.

Task

Alice can only work on one homework at a time. Help her maximize her self-awarded score!

Input data

The first line of the input contains a single integer TT, the number of test cases. TT test cases follow, each preceded by an empty line.

Each test case consists of:

  • a line containing integers NN, MM.
  • NN lines, the ii-th of which consisting of integers SiS_{i}, DiD_{i}.

Output data

The output must contain TT lines corresponding to the test cases, each consisting of integer PP, the maximum number of points Alice can reward herself with.

Constraints and clarifications

  • 1T10 0001 \le T \le 10\ 000
  • 1N200 0001 \le N \le 200 \ 000
  • 1M1 000 000 0001 \le M \le 1 \ 000 \ 000 \ 000
  • 1Si,DiM1 \le S_i, D_i \le M for each i=0N1i=0 \ldots N-1
  • The sum of NN across all test cases does not exceed 200 000200 \ 000.
# Points Constraints
1 0 Examples
2 7 Di=MD_i = M for each i=0N1i = 0 \ldots N - 1
3 12 Si=S0S_i = S_0 for each i=1N1i = 1 \ldots N - 1
4 16 The sum of NN across all test cases does not exceed 2020.
5 22 The sum of NN across all test cases does not exceed 5 0005\ 000.
6 43 No additional constraints

Example

stdin

3
3 2
1 1
1 1
1 1
6 7
1 1
2 2
3 7
2 2
2 2
3 7
4 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000

stdout

3
6
2

Explanation

In the first sample case, Alice has 33 tasks and 22 seconds to work on them. She can complete task 00 in the first second, which is within its deadline, so she gets 22 points for it. Then, she can do task 11 in the second second, so she finishes it after its deadline, but still within her total available time of 22 seconds, so she gets 11 point for it. She does not have time to do more tasks. Her total score is 33 points, and this is the maximum number of points achievable.

In the second sample case, Alice can complete tasks 00, 22, and 55, all within their deadlines, and she can get 66 points for that. It can be seen that she cannot get more than 66 points with any other scheduling of the tasks.

Log in or sign up to be able to send submissions!