Bob and the apples

3.7

65 votes
Problem

Bob goes to the fruit shop to buy apples. There are N apples numbered from 1 to N where the vitamin value of the ith apple is Vi and the price of the ith apple is Pi.

He wants to buy apples such that the sum of the price does not exceed M. He has one special magic spell. By using it, he can halve the price (floor value) of any apple present in a shop. He can use this spell at most one time.

Your task is to find the maximum vitamin Bob can get.

Input format

  • The first line contains an integer T denoting the number of test cases.
  • The first line of each test case contains two space-separated integers N and M.
  • The next N lines contain two space-separated values Vi and Pi.

Output format

For each test case, the only line must contain an integer denoting the maximum vitamin Bob can get.

Constraints

1T10

1N1000

1M1000

1Vi105

1Pi103

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Here, Shengij will perform the magic spell on apple number 1 and he will buy 1st and 2nd apples to maximize the total vitamin.

Editor Image

?