Environment Protection
Time limit1sMemory limit128 MB
Given rational function boundaries of two underground layers, find the digging depth d so the exposed middle-layer area equals a target A, printed to five decimals.
- Level
Hard8 of 10
- Topics
- Binary search, Math, Geometry, Implementation
- Solved
- No attempts yet
Problem
Arsenic & Cyanide Mining (ACM) is a corporation that has recently decided to start developing mines in the lands near your hometown. As a member of the citizens' regulatory committee for ACM's operations, your task is to control how much the corporation can mine from those lands, so that you keep the jobs and other benefits without sacrificing the environment or the health of the local residents.
ACM plans to mine several rectangular patches of land. A patch has width , can be dug down to a maximum depth , and has a flat surface which we consider to be at depth . The minerals in a patch are organized in three layers, which may vary in depth along the width of the patch but always keep the same profile along its whole length. This is why ACM cares only about the profile along the width of each patch, and has performed exploratory work to determine its shape precisely. The two interfaces between the three layers can be described by two functions and : the first is the boundary between the top layer and the middle layer, and the second is the boundary between the middle layer and the bottom layer. These functions always satisfy
so the layer boundaries never touch. Each function has the form , where
for and a certain integer . Two example patches are described in the table below.
ACM digs everything in a patch down to a certain digging depth and sells all the extracted minerals. However, the minerals in the top and bottom layers are essentially worthless, so the profit comes exclusively from the middle layer. In fact, the profit is proportional to the area of the part of the middle layer that lies at depth at most in the profile. Given the description of a patch and an integer , determine the digging depth you should allow so that ACM obtains an area of the middle layer in the profile equal to exactly . For the first example patch, obtaining area requires digging depth ; for the second example patch, obtaining area requires digging depth .
Input
Each test case is described by five lines. The first line contains four integers , , and , where is the width of the patch (), is its depth (), is the required area of the middle layer in the profile (), and defines the interfaces and as explained above (). Each of the next four lines contains integers between and , inclusive. The second line gives the coefficients of from to ; the third line gives the coefficients of from to ; the fourth line gives the coefficients of from to ; the fifth line gives the coefficients of from to .
The input contains several test cases; read until the end of input. Within each test case is strictly less than the total area of the middle layer in the profile, and there is a single value whose digging depth yields an area of exactly . Moreover, , , and for .
Output
For each test case, output one line with the digging depth that ACM should be allowed so that it obtains an area of exactly from the middle layer in the profile. Print as a decimal number with exactly five digits after the decimal point, rounded if necessary.