Zombie's Treasure Chest
Time limit1sMemory limit128 MB
Given a chest capacity and two unlimited gem types with sizes and values, maximize total value of gems that fit.
- Level
Medium7 of 10
- Topics
- Math, Number theory, Brute force, Greedy
- Solved
- No attempts yet
Problem
A band of brave warriors reaches a lost village. They are lucky enough to find piles of treasure and a large treasure chest, but also a horde of angry zombies.
The warriors decide to defeat the zombies and haul all the treasure home. After a brutal battle that lasts from morning until night, they discover that the zombies are undead and cannot be killed.
Still, the treasure cannot be left behind. The catch is that the chest has limited capacity, so not every gem can be taken. There are only two kinds of treasure: emeralds and sapphires. Every emerald has the same size and value, and there is an unlimited supply of them; the same holds for sapphires.
Given the capacity of the chest and the size and value of each kind of gem, compute the maximum total value the warriors can carry away. Formally, choose non-negative integers and with that maximize .
Input
The first line contains the number of test cases ().
Each test case is a single line with five integers : the capacity of the chest, the size and value of one emerald, and the size and value of one sapphire. All integers are positive and fit in a signed 32-bit integer.
Output
For each test case, print one line with the case number and the maximum total value of treasure that can be carried in the chest. Use the format Case #k: value, where is the test case number starting from 1.