Hide

Problem C
Fight to Survive

You are the head of a group of survivors in the zombie apocalypse.

Just recently you’ve heard word of an incoming zombie horde heading to your facility. As commander in chief the responsibility falls on to you to prepare for the incoming invasion.

Luckily these zombies are very slow, allowing you and your team to easily pick them off one by one. Every zombie has a finite amount of health, $z$, and every survivor has their own health, $h$, as well.

You and your team have devised the following strategy for dealing with the horde. The healthiest survivor will attack the closest zombie. In order to reduce the angle of attack, you and your team have created a funnel that allows the zombies to approach in single file.

There may be better strategies, but this was the one you and your team have chosen and failure to comply will result in a mutiny.

Strategy

Over the course of the stand-off two possible events can happen:

  1. A zombie approaches the shelter, and stands in line outside of the funnel.

  2. The next zombie is attacked by the healthiest survivor.

During the battle between a zombie and a survivor, the survivor’s health is reduced by the health of the attacking zombie and vice versa. If the zombie is too strong then the survivor’s health is completely reduced and the zombie’s health is reduced by the survivor’s lost health. An additional survivor will be required to save them, in which case the same process will repeat until either no survivors remain or the zombie is eliminated (it is possible for a single sufficiently powerful zombie to destroy your whole team). If the survivor and zombie have the same amount of health then the zombie will be killed and the survivor’s health will be reduced to $0$, sending them to the medical ward.

Once a survivor has had their health completely reduced they are put into the medical ward where they await treatment. Otherwise if they survive a zombie attack event they’ll take a break to recuperate, making them unavailable for the next event afterwards.

If a survivor returns to base and they have the same health as another survivor, then the survivor with the highest maximum, or original health, goes first.

As the team’s only doctor, you do not participate in the battle. Instead, starting at the beginning of the battle, at the beginning of every $m$th event, a new batch of medicine is prepared. This medicine can be used to heal one person in the medical ward, and as the doctor you choose to always heal the person with the most starting health. This medicine however expires quickly and must be used as soon as it is prepared. The healed person returns to the pool of available fighters and is available for whatever event occurs next, but their health is reduced to half the amount it was at the beginning of the invasion rounded down (if they started with $1$ health, the medicine is ineffective and they stay in the medical ward).

Using the strategy outlined above, can your team survive the zombie onslaught or do you eventually get overrun?

Input

Input begins with two space-separated integers indicating the number of survivors $1\le S\le 25$, and the rate at which you can produce medicine $1 \le m \le 50$.

The next line contains $S$ space-separated integers indicating the health $1 \le h_ i \le 255$ for the $i$th survivor. The third line contains a single integer $1 \le e \le 50$ indicating the number of events. Now the battle begins and $e$ lines follow. Each of the subsequent lines indicate an event. They are either of the form APPROACH $z$, indicating a new zombie with health $1 \le z \le 255$ approaches battle, or just the string ATTACK, indicating that it’s time to attack the next zombie.

It is guaranteed that there will be an ATTACK command only if there are zombies to attack, and that the number of ATTACK commands equals the number of APPROACH commands.

Output

Output is a single line containing either the string success, if your team is able to withstand the zombies, or overrun if there are no survivors available to attack the next zombie. Note that even if all survivors are in the medical ward at the end, you have still withstood the zombies because the doctor is still alive.

Explanation of Sample 1

A single survivor is waiting with $100$ health, not counting the doctor (you). Suddenly zombies are seen approaching the battlefield, the first with $12$ health and the second with $13$. The first zombie gets too close and is attacked by the survivor, killing the zombie. While the survivor is recuperating, the second zombie enters the base. With no one available to fight it, the zombie gets past the defenses and eats your brain.

You are overrun.

Explanation of Sample 4

You have three survivors with healths $100$, $27$, and $23$. Eight events occur, with medicine available on every eighth event (and therefore on the last event).

In the first event, a supercharged zombie with $100$ health approaches the funnel, and comes too close to the base in the second event, requiring an attack. You send out the strongest survivor who also has $100$ health against the zombie. The evenly-matched foes fight until they both have no health left, killing the zombie and sending the survivor crawling back to the medical ward.

In the third event, a second zombie with $12$ health approaches, requiring a second attack in the fourth event. The current healthiest survivor has $27$ health, and they manage to defeat the zombie, taking $12$ points of damage resulting in $15$ health left.

A third zombie with $13$ health approaches in the fifth event, and in the sixth event the third survivor, with $23$ health, begins their first fight, killing the zombie and emerging with $10$ health remaining.

In the seventh event, the final menacing zombie with $75$ health approaches, and attacks in the eighth and final event. Fortunately, you’ve managed to prepare a batch of medicine in the nick of time, and give it to the first survivor who recovers to $50$ health. The first survivor, once again the healthiest, gives their all in the fight, doing $50$ damage to the zombie. This doesn’t settle things yet, so they have to return right back to the medical ward, leaving the zombie with $25$ health.

The second survivor, now with $15$ health, does their part in the battle, reducing the zombie to $10$ health, but ultimately has to join the first survivor in the ward. The third survivor (also with $10$ health), who spent the seventh event recuperating from battle, takes up the mantle of the first two and engages in one last desperate stand against the final zombie. When the dust clears, the zombie is defeated and all the survivors rest in the medicine ward.

With no more zombies in sight, you tend to the exhausted survivors and write down a single word summing up the terrifying day as you stare into the sunset—success!

Sample Input 1 Sample Output 1
1 2
100
4
APPROACH 12
APPROACH 13
ATTACK
ATTACK
overrun
Sample Input 2 Sample Output 2
2 2
100 100
4
APPROACH 12
APPROACH 13
ATTACK
ATTACK
success
Sample Input 3 Sample Output 3
5 3
20 30 12 15 9
12
APPROACH 20
APPROACH 25
ATTACK
APPROACH 15
APPROACH 26
ATTACK
APPROACH 38
APPROACH 14
ATTACK
ATTACK
ATTACK
ATTACK
overrun
Sample Input 4 Sample Output 4
3 8
100 27 23
8
APPROACH 100
ATTACK
APPROACH 12
ATTACK
APPROACH 13
ATTACK
APPROACH 75
ATTACK
success

Please log in to submit a solution to this problem

Log in