Compute sunlight hours for each rooftop from the sky angles blocked by taller buildings on both sides.
Medium7StackGeometryMathNo attempts yetTime limit4sMemory limit256 MBRoman tenancy law recognized a right to sunlight for every resident, whatever their status. Many of the health benefits of good sun exposure were already known back then.
A city plan reviewer therefore starts by measuring how the proposed buildings divide that resource. An avenue runs from west to east and carries N buildings. The i-th building from the west stands at position Xi, is Hi meters tall, and is infinitesimally thin.
The sky covers 180 degrees, from the western horizon to the eastern horizon, and the sun crosses those 180 degrees at a constant rate over 12 hours. Look at the sky from the top of building i, the point (Xi,Hi). Another building j hides the sky from the horizon on its own side up to the direction of its top (Xj,Hj). If that direction points below the horizontal, building j hides no sky at all. When A degrees of sky are left uncovered, the top of building i is in sunlight for 12A/180 hours.
Find how long the top of each building is in sunlight.
The first line contains the number of buildings N (1≤N≤2×105).
Each of the next N lines contains two integers Xi and Hi (1≤Xi,Hi≤109), the position and the height of one building in meters. The buildings are listed from west to east, so X1<X2<⋯<XN.
Print N lines. On the i-th line, print how many hours the top of the i-th building is in sunlight, rounded to six decimal places.