PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000412. Chia diện tích hình vuông II (Separate Squares II)

    ID: 3539 Loại: Thông thường 2000ms 256MiB Tried: 0 Đã chấp nhận: 0 Độ khó: 1 Đăng bởi: Nhãn>Binary searchSweep line techniqueSegment treeCoordinate compressionComputational geometry basics
HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Chia diện tích hình vuông II (Separate Squares II)

Separate Squares II

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn axis-aligned squares in the coordinate plane. Square ii has lower-left corner (xi,yi)(x_i,y_i) and side length lil_i. Squares may intersect. The covered region is the union of all squares, so any overlap contributes area only once. Find the smallest height hh at which the horizontal line y=hy=h divides this union into two regions of equal area. Points on the line itself contribute zero area.

Input

The first line contains integer nn. Each of the following nn lines contains three integers xi,yi,lix_i,y_i,l_i for square ii.

Output

Print the minimum required height as a real number. The absolute error must not exceed 10−510^{-5}.

Subtasks

  • Subtask 1 (20 points): 1≤n≤301\le n\le 30; 0≤xi,yi≤1090\le x_i,y_i\le10^9; 1≤li≤1091\le l_i\le10^9 for every 1≤i≤n1\le i\le n; ∑i=1nli2≤1015\sum_{i=1}^n l_i^2\le10^{15}.
  • Subtask 2 (30 points): 1≤n≤10001\le n\le 1000; 0≤xi,yi≤1090\le x_i,y_i\le10^9; 1≤li≤1091\le l_i\le10^9 for every 1≤i≤n1\le i\le n; ∑i=1nli2≤1015\sum_{i=1}^n l_i^2\le10^{15}.
  • Subtask 3 (50 points): 1≤n≤500001\le n\le 50000; 0≤xi,yi≤1090\le x_i,y_i\le10^9; 1≤li≤1091\le l_i\le10^9 for every 1≤i≤n1\le i\le n; ∑i=1nli2≤1015\sum_{i=1}^n l_i^2\le10^{15}.

Examples

Input

2
0 0 1
2 2 1

Output

1.00000

Explanation

The two disjoint squares each have area 1. At height 1 the first is below the line and the second above it. Heights in [1,2][1,2] balance the areas, but smaller heights leave less than 1 below. The minimum is 1, illustrated on the left. Examples

Input

2
0 0 2
1 1 1

Output

1.00000

Explanation

The smaller square is inside the larger one, so the union area is 4 rather than 5. At height 1 the region below is 2 units wide and 1 unit high, giving area 2; the region above also has area 2. Lower heights leave less than 2 below. The answer is 1.