CSES - Datatähti Open 2017 - Ice cream
  • Time limit: 1.00 s
  • Memory limit: 512 MB

Uolevi is going to buy two portions of ice cream: one for Maija and one for himself. For each possible choice, you know its price and weight. You also know the maximum amount of money Uolevi can use.

Your task is to find out the maximum total weight of the ice cream. Note that Uolevi may also buy two similar portions.


The first input line contains two integers n and x: the number of choices, and the money Uolevi has.

After this, the input contains n lines. Each line describes one choice and contains two integers h and p: the price and weight of the choice.

You can assume that there is at least one solution.


You should print one integer: the maximum total weight.

Example 1


3 10
1 1
5 4
9 8



Explanation: Uolevi buys portions with prices 1 and 9.

Example 2


2 7
4 2
3 5



Explanation: Uolevi buys two portions with price 3.


  • 1 \le n \le 100
  • 1 \le x,h,p \le 1000


You will get 100 points for the task if your program produces a correct answer for each test case, and otherwise you will get 0 points.