Gift

Interview

Time limit1sMemory limit128 MB

Summary
Given each friend's item price and shipping cost and one coupon that halves a single item price, find the most gifts buyable within budget B.
Level

Medium4 of 10

Topics
Sorting, Greedy, Prefix sum, Brute force
Solved
No attempts yet

Problem

Before leaving for the army, Siheum wants to give a present to each of the NN friends who spent time with him. He has BB won.

Friend ii wants a present that costs PiP_i won, and shipping costs SiS_i won. So sending a present to friend ii requires Pi+SiP_i + S_i won.

Siheum has exactly one coupon that halves the price of a present. If he uses it on friend ii, then only ⌊Pi/2⌋+Si\lfloor P_i / 2 \rfloor + S_i won is needed to send that friend's present. (The coupon applies only to the present's price, not to the shipping fee.)

Find the maximum number of friends to whom Siheum can send a present.

Input

The first line contains the number of friends NN and the amount of money BB, separated by a space. (1≤N≤10001 \le N \le 1000, 1≤B≤1,000,000,0001 \le B \le 1{,}000{,}000{,}000)

Each of the next NN lines contains the price PiP_i of the present that friend ii wants and the shipping fee SiS_i, separated by a space. (0≤Pi,Si≤1,000,000,0000 \le P_i, S_i \le 1{,}000{,}000{,}000)

Output

On the first line, print the maximum number of friends to whom Siheum can send a present.

Hint

For example, suppose there are 55 friends and B=24B = 24 won, with each friend's (Pi,Si)(P_i, S_i) equal to (4,2),(2,0),(8,1),(6,3),(12,5)(4, 2), (2, 0), (8, 1), (6, 3), (12, 5). If friends 1, 2, and 4 are bought at full price and the coupon is used on friend 3, the total cost is (4+2)+(2+0)+(⌊8/2⌋+1)+(6+3)=6+2+5+9=22(4+2) + (2+0) + (\lfloor 8/2 \rfloor + 1) + (6+3) = 6 + 2 + 5 + 9 = 22 won. This is within the 2424 won budget, so all four presents can be sent and the answer is 44. Using the coupon on friend 1 or friend 4 gives the same result.

Examples1

  1. Example 1

    Input
    5 24
    4 2
    2 0
    8 1
    6 3
    12 5
    
    Expected output
    4