This page is still under construction.

Parts of this page are still being built. What you see may change.

Heroes of Might and Magic

Time limit1sMemory limit128 MB

Summary
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 HPHHP_H hit points and MPHMP_H mana points and knows three spells. Each spell costs one mana point:

  • Lightning Bolt — removes LPL_P hit points from the pack, where PP is the square the pack currently stands on.
  • Teleport — moves the pack to any square from 11 to NN (never onto square 00, where the hero stands).
  • Heal — adds dHd_H hit points to the hero. The hero's hit points can never exceed HPHHP_H; any excess is discarded.

Each monster has HPMHP_M hit points, and the pack acts as one group. If the pack currently has HH hit points, it consists of ⌈H/HPM⌉\lceil H / HP_M \rceil monsters (the ceiling is the smallest integer not less than its argument). The pack starts with NMN_M monsters, i.e. NM⋅HPMN_M \cdot HP_M 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 N+1N + 1 squares numbered 00 through NN. The hero stands on square 00 and never moves. The pack starts on square NN.

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 00 mana points and at least one monster is still alive, the hero is defeated.
  • Pack's turn. From square PP the pack moves min⁡(V,P−1)\min(V, P - 1) squares toward the hero, i.e. to square max⁡(P−V,1)\max(P - V, 1); it never enters square 00. If the pack ends its move on square 11, it strikes the hero and reduces the hero's hit points by KK, 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: NN, HPHHP_H, MPHMP_H, HPMHP_M, NMN_M, VV, dHd_H, with 1≤N≤101 \le N \le 10, 2≤HPH≤1002 \le HP_H \le 100, 1≤MPH≤501 \le MP_H \le 50, 1≤HPM≤101 \le HP_M \le 10, 1≤NM≤101 \le N_M \le 10, 1≤V≤N1 \le V \le N, and 1≤dH<HPH1 \le d_H < HP_H.

The second line contains NN integers L1,L2,…,LNL_1, L_2, \ldots, L_N (1≤LP≤101 \le L_P \le 10), separated by spaces, where LPL_P is the Lightning Bolt damage dealt when the pack stands on square PP.

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.

Examples4

  1. Example 1

    Input
    2 3 2 1 2 1 1
    1 1
    
    Expected output
    VICTORIOUS
    2
    
  2. Example 2

    Input
    2 3 2 3 1 1 1
    1 1
    
    Expected output
    DEFEATED
    
  3. Example 3

    Input
    4 4 3 1 4 1 1
    3 1 1 1
    
    Expected output
    VICTORIOUS
    3
    
  4. Example 4

    Input
    1 6 5 1 4 1 3
    1
    
    Expected output
    VICTORIOUS
    5