Navi and his friend
Practice
3.8 (275 votes)
Approved
Bit manipulation
Easy
Open
Ready
Problem
36% Success 3550 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Navi is a famous shopkeeper in his locality. He gives discounts to his regular customers. Some new rules have been made due to which he is in trouble. According to the new rules, any shopkeeper can sale his items to only one customer in a day. But every customer has some issues like the total money they have or the total weight they can handle at a time or number of items they are interested in. Navi’s friend has decided to help Navi and he promised him that he will purchase items from his shop daily and try to maximize his sale in terms of total price with satisfying the count of items and weight of the items . He will give his requirements as Wmax (maximum weight he can carry) and C (maximum count of the items he can carry). Now Navi is interested in knowing the total price of the items he can sell.

Input

First line of input will contain D (total number of days). Then for each day first line will contain N (Number of items) . Next each N lines will contains two integers P (price of ith item on that day) and W(weight of ith item on that day) separated by a space. Last line for the input of the particular day will contain Wmax and C separated by a space.

Output

For each day output “For Day #day_number:” then in next line print the maximum total price. If his friend is not able to purchase any of the item then print -1.

Constraints

1 < = D < = 10

1 < = N < = 16

1 < = C < = 20

1 < = Pi , Wi , Wmax < = 109

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
6 votes
Tags:
AlgorithmsApprovedBit ManipulationCircuitsDynamic ProgrammingEasyGame Theory
Points:30
57 votes
Tags:
ApprovedBit ManipulationCombinatoricsEasyMathOpenReady
Points:30
21 votes
Tags:
AlgorithmsDynamic ProgrammingEasy