Gift
InterviewTime limit1sMemory limit128 MB
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 friends who spent time with him. He has won.
Friend wants a present that costs won, and shipping costs won. So sending a present to friend requires won.
Siheum has exactly one coupon that halves the price of a present. If he uses it on friend , then only 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 and the amount of money , separated by a space. (, )
Each of the next lines contains the price of the present that friend wants and the shipping fee , separated by a space. ()
Output
On the first line, print the maximum number of friends to whom Siheum can send a present.
Hint
For example, suppose there are friends and won, with each friend's equal to . If friends 1, 2, and 4 are bought at full price and the coupon is used on friend 3, the total cost is won. This is within the won budget, so all four presents can be sent and the answer is . Using the coupon on friend 1 or friend 4 gives the same result.