Blocks&Balls
Time limit2sMemory limit512 MB
Given a container with fixed blocks and balls inside, find the water level where water volume v fills the region below that height.
- Level
Medium7 of 10
- Topics
- Binary search, Geometry, Math, Prefix sum
- Solved
- No attempts yet
Problem
A child on a space station plays with a toy called Blocks&Balls. The toy is one rectangular container together with several small rectangular blocks and several balls floating inside it. There is no gravity, so the blocks and the balls stay where they were placed instead of sinking to the bottom.
The child wonders how high the surface would rise after pouring water into the container. Water does not gather at the bottom in orbit, so the experiment is impossible up there, but the level can still be computed.
The base of the container is a rectangle of width and length , and the container is infinitely tall. The base sits at height . Every block is a rectangular box whose faces are parallel to the faces of the container. A block with center height , width , length and height occupies the heights from to , and a horizontal cut through it has area . Every ball has center height and radius .
You pour water of volume . The water gathers from the bottom, and the blocks and the balls stay fixed, so the part of each object below the surface takes up room the water would otherwise fill. The water level is the height at which the volume between height and height , minus the volume the blocks and the balls occupy inside that range, is exactly . Compute .
Input
The first line contains the number of test cases . ()
The first line of each test case contains the real numbers , , and the integers , : the width of the container, its length, the volume of the poured water, the number of blocks and the number of balls. (, , )
Each of the next lines contains the real numbers , , , of one block: the height of its center, its width, its length and its height. (, , , , )
Each of the next lines contains the real numbers , of one ball: the height of its center and its radius. (, , )
Every real number is given with at most six digits after the decimal point. The input is always consistent: no two objects intersect, and every object fits inside the container. The sum of over all test cases is at most .
Output
For each test case, print the water level on its own line, rounded to exactly six digits after the decimal point with the trailing digits written out. If the answer is exactly , print 3.000000.
If several values of satisfy the condition, print the smallest one. The water level never exceeds , and the exact water level is always at least away from the midpoint of two neighboring multiples of , so the rounded value is unambiguous.