P25298 [AtCoder] Zabuton
提高+
题目描述

Problem Description

In the final round of CODE FESTIVAL of a certain year, there were $ N $ participants. Participant $ i $ has a height of $ H_i $ and a strength of $ P_i $.

Ringo wants the participants to play a game of stacking zabutons (cushions).

The participants can line up in any order, and one by one, they will stack zabutons in one place. Initially, no zabutons are stacked. When it's participant $ i $'s turn, if the number of zabutons already stacked is $ H_i $ or less, they will stack exactly $ P_i $ zabutons. Otherwise, they will give up and stack none.

Ringo wants as many participants as possible to stack zabutons. By cleverly arranging the order of participants, what is the maximum number of participants who can stack zabutons?

Input Format

The input is given from the standard input in the following format:

$ N $ $ H_1 $ $ P_1 $ $ H_2 $ $ P_2 $ $ : $ $ H_N $ $ P_N $

Output Format

Output the maximum number of participants who can stack zabutons.

Sample Input and Output

Sample Input #1

3
0 2
1 3
3 4

Sample Output #1

2

Sample Input #2

3
2 4
3 1
4 1

Sample Output #2

3

Sample Input #3

10
1 3
8 4
8 3
9 1
6 4
2 3
4 2
9 2
8 3
0 1

Sample Output #3

5

Notes/Hints

Constraints

  • $1 \leq N \leq 5000$
  • $0 \leq H_i \leq 10^9$
  • $1 \leq P_i \leq 10^9$

Sample Explanation 1

If the participants line up in the given order, only the 1st and 3rd participants can stack zabutons. There is no order where all three participants can stack zabutons, so the answer is $ 2 $.

Sample Explanation 2

If the participants line up in the order of 2nd, 3rd, and then 1st, all of them can stack zabutons.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 0 2 1 3 3 4
样例输出
2