Witcher Potion
Time limit1sMemory limit512 MB
Given up to 8 potions with energy and toxicity, determine how many identical monsters Geralt can beat given energy, poison, and time rules.
- Level
Hard8 of 10
- Topics
- Brute force, Simulation, Bit manipulation, Greedy
- Solved
- No attempts yet
Problem
In a mythical world there is a fighting contest. Each contestant faces monsters one at a time and defeats as many as possible before being knocked out. The Witcher tribe has an edge over the others, because a Witcher drinks energy potions that are also poisonous. A potion raises energy at once, and a Witcher is never knocked out while energy remains. The poison limits how often a potion helps: a Witcher may drink at most one bottle right after defeating a monster.
Geralt, a legendary Witcher, enters the tournament with potion bottles. Bottle has strength and toxicity . Drinking it raises his energy by units, but energy never rises above 100. It also raises the toxicity in his blood by units. If blood toxicity reaches 100 Geralt is knocked out, so he never drinks a bottle that would take it that far.
His body clears poison quickly. In minutes blood toxicity drops by units, and it never falls below 0. That is what lets him safely drink another bottle later on.
All monsters are the same. Defeating one costs energy units and takes minutes. If Geralt has or fewer energy units he cannot defeat a monster, and the contest is over for him.
Geralt starts with 100 energy units and 0 blood toxicity. Analyse the potion data and the monster data, then report the largest number of monsters Geralt can defeat.
Input
The first line contains the number of test cases (). Each test case is given on four lines.
- Line 1: and , the energy and the time Geralt spends on each monster (, )
- Line 2: , the number of potion bottles Geralt carries ()
- Line 3: , the strength of bottles 1 to ()
- Line 4: , the toxicity of bottles 1 to ()
Output
For each test case print the largest number of monsters Geralt can defeat, one line per case.
Notes
Geralt may skip the potion after defeating a monster even when bottles are left in his inventory. Each bottle is drunk at most once. When no bottle is left, or when he chooses not to drink, he fights on with the energy he still has.
One fight follows a fixed order. He spends energy and minutes to defeat the monster, his blood toxicity drops by units (never below 0), and only after that may he drink one bottle.