AlgoUniversity
  • Go Back
Discussion
Grant Wishes :

Author

hardik kapoor

Difficulty Level : Medium

Submissions : 118

Asked In : Pine-Labs

Marks :10

: 2 | : 3

Zasho is a popular genie.Being a genie, he's in the business of granting wishes, and a lot of people ask him for help. However, his power is limited - currently it is p units.

To grant the i-th wish, Zasho needs to have to have at least x units of power. After a wish is granted, his power rating changes by y (y can be positive or negative). His power should not dip below zero at any point.

Zasho wants to grant the maximum number of wishes possible so that he remains popular. Please help him figure this out.

In other words, find the maximum possible size of the subset of wishes so that Zasho has enough power before starting each, and has non negative power after completing each wish. Wish for the selected subset can be granted In any order.

Input

First line contains two wishes n (1 <= n <= 100) and p (1 <= p <=30000). The next n lines contain the wishes, one per line. The I-th wish is represented as a pair of integers x and y (1 <= x <= 30000 , -300 <= y <= 300)

Output

Output a single integer, the maximum size of the subset.

Examples

Input
3 5
4 -5
4 -2
1 3
Output
3
Input
5 2
6 8
6 10
7 3
10 9
4 7
Output
0

Note

A possible order <2,3,1> exists.

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.