#P11328. Wabbit Contest Badge Collection

    ID: 13405 Type: Default 1000ms 256MiB

Wabbit Contest Badge Collection

Wabbit Contest Badge Collection

You are a Wabbit with an initial level of 00. You want to participate in contests to increase your strength and collect badges. There are NN contests in total. The iith contest is characterized by two integers LiL_i and XiX_i. You can participate in contest ii if and only if your current level satisfies Li\leq L_i. When you participate, your level increases by XiX_i and you earn one badge. You may attempt the contests in any order. Determine the maximum number of badges you can collect by choosing the optimal sequence of contests.

inputFormat

The first line contains a single integer NN (1N1051\le N\le 10^5) representing the number of contests. Each of the following NN lines contains two space-separated integers LiL_i and XiX_i, where 0Li,Xi1090\leq L_i, X_i\leq 10^9.

outputFormat

Output a single integer — the maximum number of badges you can collect.

sample

2
1 100
10 1
2

</p>