#P3997. Area Covered by Concentric Sectors
Area Covered by Concentric Sectors
Area Covered by Concentric Sectors
Given n sectors that are concentric (sharing the same center), each defined by its radius r and an angular interval \( [s,t] \) (in radians), compute the total area that is covered by at least \( k \) sectors.
Each sector covers the region from the center (radius 0) up to radius r and spans the angles from \( s \) to \( t \). In other words, the area of a full sector is given by the formula \[ A=\frac{1}{2}r^2(t-s), \] but note that the sectors may overlap partially. The task is to determine the total area which is covered by at least \( k \) sectors.
Hint: Since all sectors share the same center, for any fixed direction (angle), a sector covers all radii from 0 up to its radius r if that angle lies in its interval. Thus, for any angular segment where the set of sectors covering that entire segment is constant, the coverage at radius x equals the number of sectors whose radius is at least x. The area in such an angular slice with angular width \( \Delta\theta \) contributed by the region with at least \( k \) covering sectors is \( \frac{\Delta\theta}{2}\,R^2 \), where \( R \) is the \( k \)-th largest radius among those active sectors.
inputFormat
The first line contains two integers n and k (1 ≤ k ≤ n), where n is the number of sectors.
Each of the following n lines contains three real numbers: r, s and t. Here, r (\( > 0 \)) is the radius of the sector, and \( s \) and \( t \) (with \( 0 \le s < t \le 2\pi \)) represent the starting and ending angles (in radians) of the sector respectively.
outputFormat
Output a single floating point number: the total area that is covered by at least \( k \) sectors. The answer is accepted if the absolute or relative error does not exceed \( 10^{-6} \).
sample
1 1
1 0 1.57079632679
0.785398