Bob and the apples
Practice
3.7 (65 votes)
Dynamic programming
Algorithms
Introduction to dynamic programming 1
Problem
88% Success 9354 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
Bob goes to the fruit shop to buy apples. There are \(N\) apples numbered from \(1\) to \(N\) where the vitamin value of the \(i^{th}\) apple is \(V_i\) and the price of the \(i^{th}\) apple is \(P_i\).
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 \(V_i\) and \(P_i\).
Output format
For each test case, the only line must contain an integer denoting the maximum vitamin Bob can get.
Constraints
\(1 \le T \le 10\)
\(1 \le N \le 1000 \)
\(1 \le M \le 1000\)
\(1 \le V_i \le 10^5\)
\(1 \le P_i \le 10^3\)
Submissions
Please login to view your submissions
Similar Problems
Points:30
8 votes
Tags:
Easy
Points:30
97 votes
Tags:
Dynamic ProgrammingEasyOpenRecursion
Points:30
7 votes
Tags:
CombinatoricsDynamic ProgrammingAlgorithmsStringIntroduction to Dynamic Programming 1
Editorial