Rout 66

Time limit1sMemory limit128 MB

Summary
Simulate an invader whose strength drops after each stronghold it breaks, processing strongholds nearest first, and report whether all fall.
Level

Easy3 of 10

Topics
Simulation, Sorting, Math
Solved
No attempts yet

Problem

While the Romans may have had a fancy number system, the Visigoths — led by Alareiks, known today as Alaric I — took Rome on August 24, 410. It was the first time in eight hundred years that Rome had fallen to a foreign army.

You will simulate a considerably less bloody (and less realistic) rout of defenders by a potentially overwhelming invading force.

Consider a group of invaders of strength II advancing on a stronghold whose defenders have strength JJ and whose fortifications have strength SS, at a distance DD ahead. The invaders' Routing Force FF is their strength times the distance:

F=I⋅DF = I \cdot D

and the defenders' Blocking Force BB is the defender strength times the square of the fortification strength:

B=J⋅S2B = J \cdot S^2

If F≤BF \le B, the rout fails and the invaders are driven off. If F>BF > B, the rout succeeds: every defender is driven off and the invaders advance. Their strength is then reduced by the fraction B/FB / F — the ratio of the defenders' Blocking Force to the invaders' Routing Force — and rounded up so that a successful rout always leaves at least one soldier:

Inew=⌈I(1−BF)⌉I_{\text{new}} = \left\lceil I \left(1 - \frac{B}{F}\right) \right\rceil

Once the invaders break through a stronghold, that stronghold's location becomes the new starting point for measuring the distance to the next stronghold, and so on, until the invaders either break through every stronghold or are completely routed.

All strongholds lie on a straight line from the invaders' starting position and must be engaged in order from nearest to furthest. No two strongholds occupy the same location within a data set.

Input

The first line contains an integer NN (1≤N≤1001 \le N \le 100), the number of data sets. Each data set consists of:

  • a line with an integer EE (1≤E≤201 \le E \le 20), the number of strongholds;
  • EE lines, each containing three space-separated integers DD, JJ, SS (1≤D,J≤100001 \le D, J \le 10000; 1≤S≤501 \le S \le 50). DD is the distance of the stronghold from the invaders' starting position (the strongholds may be listed in any order and must be processed from nearest to furthest), while JJ and SS are the defender strength and the fortification strength;
  • a line with an integer II (1≤I≤300001 \le I \le 30000), the strength of the invading force.

Output

For each data set, print ROUT! if the invaders break through every stronghold, or RETREAT! if they cannot.

Examples1

  1. Example 1

    Input
    2
    1
    10 10 5
    100
    2
    75 100 5
    10 10 5
    50
    
    Expected output
    ROUT!
    RETREAT!