#P5951. Water Level Calculation with Cubes in a Pool

    ID: 19176 Type: Default 1000ms 256MiB

Water Level Calculation with Cubes in a Pool

Water Level Calculation with Cubes in a Pool

Given a pool with a base area \(S\) and a height \(H\), and with an initial water volume \(V\), you are to compute the final water level in the pool after inserting \(n\) cubes. Each cube is specified by an edge length \(a\) and a density \(d\). We assume that the water has a density of \(1\) and ignore any effects of air. Furthermore, the cubes do not contact each other or rotate in the water.

For each cube, the displaced water volume is determined as follows:

  • If \(d < 1\) (cube floats), the displaced volume is \(d \times a^3\).
  • If \(d \ge 1\) (cube sinks), the displaced volume is \(a^3\).

The water level \(L\) in the pool is given by:

\[ L = \min\Biggl(H,\; \frac{V + \sum_{i=1}^{n} \text{displaced}_{i}}{S}\Biggr) \]

Output the final water level.

inputFormat

The input consists of multiple lines:

  1. The first line contains three numbers \(S\), \(H\), and \(V\) (base area, pool height, and initial water volume) separated by spaces.
  2. The second line contains an integer \(n\), representing the number of cubes.
  3. The next \(n\) lines each contain two numbers: \(a\) (the edge length of the cube) and \(d\) (the density of the cube).

outputFormat

Print a single number representing the final water level in the pool.

sample

10 5 50
1
2 0.5
5

</p>