403228: GYM101081 K Pope's work

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

K. Pope's worktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Karol Wojtyla was born in Wadowice in 1920. He was elected as pope John Paul II in 1978 and died in April 2th in 2005, after completing 26 years of papacy. He is one of the most important polish men in history.

Before devoting his life to religion, during the World War II, he worked in a factory of chemical products. One of his duties was to arrange boxes containing chemical products in stacks. The problem was that some of these boxes were really heavy, and others could not afford much weight over them. The managers of the factory wanted big stacks, with the highest number of boxes possible. Every box had associated two attributes: its weight (in kilograms) and the weight that it is able to afford in kilograms (including the weight of the box). For example, a box of 25 kg. and 60 kg. of resistance is able to hold at most 35 kg. on top of it.

Your task is, given a list of boxes, along with their weight and resistance, determine the maximum number of boxes that can be arranged into a stack without exceeding the resistance of any of them.

Input

The first line contains an integer T, the number of test cases.

The first line of each test case contains an integer N, the number of boxes. Each of the next N lines contains two integers, the ith has Wi and Ri, the weight and the resistance of box i, respectively.

Limits

  • 1 ≤ T ≤ 25
  • 1 ≤ N ≤ 103
  • The sum of N over all test cases will not exceed 3·103
  • 1 ≤ Wi ≤ 103
  • Wi ≤ Ri ≤ 106
Output

For each test case, print the maximum number of boxes that can be arrange into a stack.

ExampleInput
2
4
13 30
11 15
7 28
6 6
3
43 60
47 100
430 450
Output
3
2

Source/Category

加入题单

算法标签: