Diver

Time limit3sMemory limit128 MB

Summary
Given a diver moving along a vertical rope avoiding oscillating sharks whose horizontal distance follows a triangle wave, find the minimum time to reach the surface without ever coming within radius r of a shark, or report impossibility.
Level

Medium7 of 10

Topics
Binary search, Simulation, Geometry, Math
Solved
No attempts yet

Problem

A diver has just finished her mission in the depths of the ocean and needs to return to the surface. She can only move up or down along a rope that hangs straight down from her boat at the surface to her position dd feet under water.

While she was working, several sharks gathered near the rope. They do not yet consider her a threat or prey, but if she ever comes closer than rr feet to any shark, that shark immediately attacks her.

To avoid decompression sickness, the diver can descend or ascend at a speed of at most vdv_d feet per second. She also cannot go deeper than dd feet under water.

Each shark ii swims at its own constant depth of did_i feet near the rope. The speed and pattern of movement are the same for all sharks. A shark cannot stay still in the water, so to avoid sinking it constantly swims back and forth at a constant speed vsv_s: it moves away from the rope up to a distance of ww feet and then swims back to the rope again. A shark changes direction so quickly that we treat it as instantaneous. An attack also happens so quickly that we treat it as instantaneous the moment the diver enters a circle of radius rr feet around a shark.

The diver is always on the rope (her horizontal distance from the rope is 00), so the distance between the diver and a shark is the hypotenuse of the right triangle whose legs are the difference in their depths and the shark's horizontal distance from the rope, i.e. (depth difference)2+(shark’s horizontal distance)2\sqrt{(\text{depth difference})^2 + (\text{shark's horizontal distance})^2}.

Determine whether the diver can reach the surface without being attacked by a shark, and if so, how fast she can do it.

Input

The first line contains 66 integers:

  • dd (10≤d≤10010 \le d \le 100) — the initial depth of the diver.
  • vdv_d (1≤vd≤101 \le v_d \le 10) — the maximal speed of the diver.
  • nn (1≤n≤201 \le n \le 20) — the number of sharks.
  • rr (1≤r≤101 \le r \le 10) — the minimal safe distance between a shark and the diver.
  • ww (10≤w≤10010 \le w \le 100) — the maximal distance that a shark swims away from the rope.
  • vsv_s (1≤vs≤501 \le v_s \le 50) — the speed of a shark.

Then follow nn lines describing the sharks, with 33 integers per line:

  • did_i (1≤di<d1 \le d_i < d) — the depth of the ii-th shark.
  • wiw_i (0≤wi≤w0 \le w_i \le w) — the initial distance from the ii-th shark to the rope.
  • fif_i (fif_i is 11 or −1-1) — the initial direction of the ii-th shark's movement: 11 if it swims away from the rope, or −1-1 if it swims toward the rope.

Initially the diver is more than rr feet from any shark.

Output

If the diver cannot reach the surface, print IMPOSSIBLE.

Otherwise, print the minimal time needed to reach the surface, rounded to one decimal place (using round half up).

Examples1

  1. Example 1

    Input
    10 1 2 1 10 1
    6 4 -1
    1 1 1
    
    Expected output
    11.4