P5951 [BalticOI 2003] Barrel

Background

A big pool.

Description

Given a pool with bottom area $S$ and height $H$. There is currently water with volume $V$ in it. Then $n$ cubes are put into the pool. For each cube, its edge length and density are given. Compute the final height of the water level in the pool. Note: We ignore any effect of air forces. Assume that the cubes do not touch each other and do not rotate in the water, and assume the density of water is $1$.

Input Format

The first line contains three integers $S, H, V$. The second line contains an integer $n$. The next $n$ lines each contain two real numbers: the edge length and the density of the cube.

Output Format

Output the final height of the water surface. An error of at most $10^{-7}$ is accepted.

Explanation/Hint

For $100\%$ of the testdata, $1 \le S, H, V \le 10000$, and $1 \le n \le 1000$. Constraints Translated by ChatGPT 5