Heroes of Might and Magic
Time limit1sMemory limit128 MB
Decide whether a mage hero can wipe out a monster pack using lightning, teleport, and heal, and give the minimum number of spells needed.
- Level
Medium6 of 10
- Topics
- BFS, Simulation, Greedy, Implementation
- Solved
- No attempts yet
Problem
In the new version of the famous game "Heroes of Might and Magic", the heroes themselves take an active part in battles. A powerful mage hero can even defeat a pack of monsters alone, without any supporting army. In this problem you must decide whether your mage hero can win a face-to-face fight against a pack of monsters.
The hero starts with hit points and mana points and knows three spells. Each spell costs one mana point:
- Lightning Bolt — removes hit points from the pack, where is the square the pack currently stands on.
- Teleport — moves the pack to any square from to (never onto square , where the hero stands).
- Heal — adds hit points to the hero. The hero's hit points can never exceed ; any excess is discarded.
Each monster has hit points, and the pack acts as one group. If the pack currently has hit points, it consists of monsters (the ceiling is the smallest integer not less than its argument). The pack starts with monsters, i.e. hit points, and its hit points only ever decrease. The pack is destroyed once its hit points become non-positive.
The battle takes place on a one-dimensional field of squares numbered through . The hero stands on square and never moves. The pack starts on square .
The battle proceeds in alternating turns: first the hero acts, then the pack, and so on.
- Hero's turn. The hero must cast exactly one spell, paying one mana point. If, at the start of the hero's turn, the hero has mana points and at least one monster is still alive, the hero is defeated.
- Pack's turn. From square the pack moves squares toward the hero, i.e. to square ; it never enters square . If the pack ends its move on square , it strikes the hero and reduces the hero's hit points by , the current number of monsters in the pack. If the hero's hit points become non-positive, the hero is defeated.
If a Lightning Bolt reduces the pack's hit points to non-positive on the hero's turn, the hero wins immediately and the pack does not act.
Determine whether the hero can defeat the pack.
Input
The first line contains seven positive integers, separated by spaces, in this order: , , , , , , , with , , , , , , and .
The second line contains integers (), separated by spaces, where is the Lightning Bolt damage dealt when the pack stands on square .
Output
If the hero cannot win the battle, print DEFEATED.
Otherwise print VICTORIOUS on the first line and, on the second line, a single integer: the minimum number of turns (equivalently, the minimum number of spells the hero must cast) needed to reduce the pack's hit points to non-positive.