The Robbery
Time limit3sMemory limit128 MB
Given N item types where type k has exactly k identical copies, pick copies within a weight budget M to maximize total value (bounded knapsack with huge M and small N).
- Level
Medium6 of 10
- Topics
- Dynamic programming, Combinatorics, Greedy
- Solved
- No attempts yet
Problem
In the downtown of Bucharest there is a very big bank with a very big vault. Inside the vault there are very big boxes, numbered from 1 to . Inside the box with number there are exactly very big diamonds, and every diamond in that box has weight and cost .
John and Brus are inside the vault at the moment. They would like to steal everything, but unfortunately they are able to carry diamonds with a total weight not exceeding .
You may take any number of diamonds from box , from 0 up to all of them. Your task is to help John and Brus choose diamonds with a total weight less than or equal to and the maximal possible total cost.
Input
The first line contains a single integer — the number of test cases. Each test case starts with a line containing two integers and separated by a single space. The next line contains integers separated by single spaces. The following line contains integers separated by single spaces.
Output
For each test case print a single line containing the maximal possible total cost of the stolen diamonds.