cho.sh
Notes
Loading...

Water Level in Connected Tanks

Time limit

2s

Memory limit

128 MB

Problem

There are N rectangular tanks in three-dimensional space. Each tank is described by four integers: its bottom height b (0 <= b <= 1,000,000), its own height h (1 <= h <= 40,000), its width w (1 <= w <= 40,000), and its depth d (1 <= d <= 40,000).

A pipe is attached below every tank, and all pipes are connected to one another. Ignore the volume of the pipes; water is considered to occupy only the tanks.

When V units of water are poured into this system, the connected tanks fill according to one common water surface, rising from the lowest reachable tank bottoms. Given the tank information and the amount of water, determine the final height of the water surface.

Input

The first line contains the integer N (1 <= N <= 50,000).

Each of the next N lines contains four integers b, h, w, and d describing one tank.

The last line contains the water volume V (1 <= V <= 2,000,000,000).

All input values are integers.

Output

Print the final water-surface height rounded to two digits after the decimal point. An absolute error up to 10^-2 is accepted.

If the amount of water is greater than the total capacity of all tanks, print OVERFLOW.