Public Judge

pjudge

时间限制: 3 s 内存限制: 512 MB 总分: 100 可 Hack ✓
统计

Cats have nine lives, but you have 114514 lives.

Description

You have $n$ tasks to complete, where the $i$-th task takes $t_i$ days. However, human life is limited, and you only have $c$ days left.

Preparation is key; you can spend $1$ day to deeply contemplate the $i$-th task, which will reduce the time required for it by $d_i$ days. Specifically, if the time is reduced to zero or a negative number, the task can be completed instantly. However, human inspiration is limited, and each task can only be deeply contemplated once per lifetime.

You can be resurrected, and each resurrection grants you another $c$ days. The results of previous deep contemplations are preserved and do not disappear upon resurrection.

Find the minimum number of times you need to be resurrected to complete all tasks in your last life. You can assume that you cannot perform any tasks before your last life; you can only contemplate tasks. In your last life, you can both contemplate and perform tasks.

Input

The first line contains a positive integer $T$, representing the number of test cases. The format for each test case is as follows:

  • The first line contains two positive integers $n$ and $c$, representing the number of tasks and the length of one life, respectively.
  • The next $n$ lines each contain two positive integers $t_i$ and $d_i$, describing a task.

Output

For each test case, output a single non-negative integer representing the minimum number of resurrections required.

Examples

Input 1

2
3 5
17 5
5 2
15 4
2 1345
1344 1
10 10

Output 1

3
0

Note 1

For the first test case:

In the first three lives, contemplate each task once. The time required for the tasks becomes $2, 0, 3$ respectively.

In the last life, contemplate task $1$ and task $3$, then complete all tasks instantly.

A total of four lives are used, requiring three resurrections. It can be proven that no solution exists with fewer than $3$ resurrections.

For the second test case:

First, contemplate the second task, then complete the second task instantly. Then, complete the first task in the following $1344$ days.

Input 2

1
3 1
1000000000 1
1000000000 1
1000000000 1

Output 2

2999999999

Input 3

(See the provided files ex_rebirth*.in/ex_rebirth*.ans, which correspond to subtasks 2 through 5.)

Constraints

This problem uses bundled testing; you must pass all test cases in a subtask to receive points for that subtask.

For all data, $1\le T\le 1000, 1\le \sum n\le 2\times 10^5, 1\le c\le 10^9, 1\le d_i\le t_i\le 10^9$.

Subtask ID Special Properties Score
$1$ $\sum n,\sum t_i\le 7$ $10$
$2$ $n,t_i\le 30, T\le 100$ $20$
$3$ $\sum n\le 3000$ $20$
$4$ $c\ge n$ $20$
$5$ $30$

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.