Hunger Games
InterviewTime limit3sMemory limit256 MB
Choose weapons within the sack weight limit to maximize total preference.
- Level
Easy3 of 10
- Topics
- Dynamic programming
- Solved
- No attempts yet
Problem
When the Hunger Games begin, the participant from each district picks weapons out of the toolboxes. Every participant gets one sack, and each sack has a fixed weight limit. The total weight of the chosen weapons must not exceed that limit. There is only one copy of each weapon, so the same weapon cannot be packed twice.
Participants prefer different weapons. Maximize the total preference of the chosen weapons while staying within the weight limit.
Input
The first line contains an integer , the number of test cases (). The test cases follow.
Each test case consists of four lines. The first line contains an integer , the number of weapons (). The second line contains an integer , the capacity of the sack (). The third line contains integers giving the weight of each weapon in order. The fourth line contains integers giving the participant's preference value of each weapon in the same order. Every weight and every preference value is an integer between 1 and 100.
Output
For each test case, print the maximum total preference value on its own line.