V_AYP1_F - A little help for Yon

no tags 

Yonkleiderson is a very lazy student which really dislikes carrying his own books. He often asks his friends for help, they carry a certain book, a certain distance for a Price. Yonkleiderson must take N books and for each book the position and cost per meter will be given. He needs to calculate how much it will cost him to take the books from one place to the other with Yonaiker´s help. Although he can only use Yonaiker´s help once. Yonkleiderson has a limited amount of money and he is not always able to pay Yonaiker to take all his books. Yonkleiderson must calculate what is the greatest amount of books Yonaiker can carry.

Yonaiker once he picks up a book will carry it together with the rest he picks up along the way, until the final destination where he will leave all the books.

Input details:

The first line will contain two integers N and V, N represents the number of books to be picked up, V is the amount of money Yonkleiderson has. N lines will follow each with two integers B and C where B represents the position of the books and C the cost per meter of each book.

Example;

N=4 V=20

20 2

22 5

30 8

32 1

For this test case the result is 1. Only one book can be taken by Yonaiker.

The book in position 20 cost until position 22 is 4: (22-20)*2= 2*2=4.

If you want help with the first until the third book we must remember that the second book will also be taken: ((30-20)*2) +((30-22)*5) = 20 + 40 = 60.

The cost of taking the first book to the end: ((32-20)*2)+ ((32-22)*5) + ((32-30)*8) = 24+50+16=90

In the same way we start calculating from the second book, second to third: (30-22)*5=8*5=40, second to fourth: ((32-22)*5)+((32-30)*8)= 50+16=66

Third to fourth: (32-30)*8= 16 

We can observe the value of V is only 20 as such we can only pay Yonaiker for help in taking the first book to the second or the book before last to the last.

 

Output details:

The output will consist of an integer which will show the maximum amount of books with which Yonaiker can help Yonkleiderson.

 

INPUT

OUTPUT

4 20

20 2

22 5

30 8

32 1

1

 

Constraints:

0 < N < 100

0 < V < 5000000

0 < B < 300

0 < C < 20



Added by:Venezuelan Programming League
Date:2013-02-02
Time limit:5s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64