Cocktail
Time limit1sMemory limit128 MB
A cube is lowered into a vessel holding two immiscible liquids of different densities; some liquid may spill. Find the final liquid height using Archimedes' principle.
- Level
Medium7 of 10
- Topics
- Math, Implementation, Geometry, Simulation
- Solved
- No attempts yet
Problem

A cylindrical vessel of height () and bottom radius () stands on a horizontal surface. It holds two liquids that have different densities and do not mix. Let and be the densities of the first and second liquids, with , so the denser first liquid forms the lower layer and the second liquid rests on top. Let and be the heights of the two layers, with and .
A solid cube has edge length () and is made of a material of density (). The cube is lowered into the vessel so that one of its faces stays horizontal. Some liquid may spill over the rim. When it comes to rest, the cube either floats in the liquids or lies on the bottom.
Using Archimedes' principle (and neglecting damping and other minor physical effects), compute the height of the liquid column in the vessel after the cube has been placed.
Input
The single line contains the numbers , , , , , , , and , separated by spaces. All numbers are real and each has at most three digits after the decimal point.
Output
Print one real number: the resulting liquid height, rounded to exactly three digits after the decimal point.