#BS0000392. Chia đôi diện tích hình vuông I (Separate Squares I)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chia đôi diện tích hình vuông I (Separate Squares I)
Separate Squares I
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Consider axis-aligned squares. Square has bottom-left corner and side length . A horizontal line divides each square into an upper and a lower part, either of which may be empty. Add the upper areas and lower areas separately over all squares. An overlapping region contributes once for each square containing it. Find the smallest height at which these two sums are equal.

Input
The first line contains integer . Line of the next lines contains integers describing square .
Output
Print the smallest required height as a real number. The absolute error must not exceed .
Subtasks
- Subtask 1 (20 points): ; ; for every ; .
- Subtask 2 (30 points): ; ; for every ; .
- Subtask 3 (50 points): ; ; for every ; .
Examples
Input
2
0 0 1
2 2 1
Output
1.00000
Explanation
Both squares have area 1. Height 1 places the first square below and the second above. Every height from 1 to 2 balances the areas; 1 is the smallest.
Input
2
0 0 2
1 1 1
Output
1.16667
Explanation
At height , the lower areas are and , totaling . The upper sum is also . Every smaller height has a lower sum below .