AT_abc437_c [ABC437C] Reindeer and Sleigh 2

Description

There are $ N $ reindeer and one sled. The $ i $ -th reindeer has weight $ W_i $ and strength $ P_i $ . For each reindeer, choose either "pull the sled" or "ride on the sled". Here, the total strength of the reindeer pulling the sled must be greater than or equal to the total weight of the reindeer riding on the sled. What is the maximum number of reindeer that can ride on the sled? You are given $ T $ test cases. Solve each of them.

Input Format

The input is given from Standard Input in the following format: > $ T $ $ \mathrm{case}_1 $ $ \mathrm{case}_2 $ $ \vdots $ $ \mathrm{case}_T $ Each test case is given in the following format: > $ N $ $ W_1 $ $ P_1 $ $ W_2 $ $ P_2 $ $ \vdots $ $ W_N $ $ P_N $

Output Format

Output $ T $ lines. The $ i $ -th line should contain the answer for the $ i $ -th test case.

Explanation/Hint

### Sample Explanation 1 For the 1st test case, if the 3rd reindeer pulls the sled and the 1st and 2nd reindeer ride on the sled, the total strength of the reindeer pulling the sled is $ P_3=9 $ , and the total weight of the reindeer riding on the sled is $ W_1+W_2=7 $ , satisfying the condition. Since not all reindeer can ride on the sled, the answer is $ 2 $ . ### Constraints - $ 1\leq T\leq 10^5 $ - $ 1\leq N\leq 3\times 10^5 $ - $ 1\leq W_i,P_i\leq 10^9 $ - All input values are integers. - The sum of $ N $ in one input file is at most $ 3\times 10^5 $ .