The Snail
Time limit1sMemory limit128 MB
Simulate a snail that climbs a bit less each day and slides a fixed distance each night, and report whether it escapes or falls back first.
- Level
Easy3 of 10
- Topics
- Implementation, Simulation, Math
- Solved
- No attempts yet
Problem
A snail is at the bottom of a well that is feet deep and wants to climb to the top. During the day, while the sun is up, the snail climbs upward; at night, while it sleeps, it slides back down.
On the first day the snail climbs feet. However, the snail grows tired, so it climbs a little less each day. Specifically, on day the snail climbs feet. (The distance lost to fatigue is always of the first day's climbing distance.) If this value is negative, the snail does not climb at all that day (it climbs a distance of 0). No matter how far it climbed during the day, at night the snail always slides down feet.
The moment the snail's height first exceeds the well's height of feet, it leaves the well. Conversely, if after sliding at night its height becomes negative, the snail has slid back to the bottom of the well and fails. (A day consists of a period of sunlight followed by a period of darkness.)
For example, when , the snail leaves the well on the third day, as shown in the table below.
Depending on the parameters, the snail will eventually either leave the well (its height exceeds ) or slide back to the bottom (its height becomes negative). Determine which happens first, and on which day.
Input
The input consists of one or more test cases, each on a line by itself. Each line contains four integers separated by single spaces.
- : the height of the well in feet
- : the distance the snail climbs during the day in feet
- : the distance the snail slides down at night in feet
- : the fatigue factor expressed as a percentage
A line with signals the end of the input and is not processed. Otherwise all four integers are between and , inclusive. The snail never climbs a negative distance: if fatigue drops the climbing distance below zero, the snail does not climb at all that day. Regardless of how far it climbed, it always slides feet at night.
Output
For each test case, output a single line.
If the snail leaves the well (success), print:
success on day <n>
If the snail slides back to the bottom (failure), print:
failure on day <n>
where <n> is the number of the day on which the event occurs.