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

#BS0000428. Vượt qua hành lang (Getting Through)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Vượt qua hành lang (Getting Through)

Getting Through

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

Ethan must travel from one end of a straight corridor to the other without triggering its sensors. Each sensor detects people or objects entering its detection region. Ethan wants to determine how much equipment he can carry through the corridor while remaining undetected.

Ignoring height, represent the corridor by the strip between the parallel walls x=0x=0 and x=wx=w. The two ends are far beyond every sensor, toward y=−∞y=-\infty and y=+∞y=+\infty.

There are nn sensors. Sensor ii is located at (xi,yi)(x_i,y_i) and detects objects in a disk of radius rir_i around that point. Its center is inside the corridor or on a wall; its detection region may extend beyond a wall.

Represent Ethan and his equipment (or a robot sent instead) by a disk of radius RR. The disk may move continuously with arbitrary precision, without crossing a wall or entering any sensor's detection region. Find the greatest radius that can pass through undetected, interpreted as the limiting radius when clearance is just sufficient. If passage is impossible even for arbitrarily small objects, the answer is 00.

Input

The first line contains an integer ww, the corridor width.

The second line contains an integer nn, the number of sensors.

Each of the next nn lines contains three integers xi,yi,rix_i,y_i,r_i: the horizontal coordinate, vertical coordinate, and detection radius of sensor ii, respectively.

Output

Print one real number on a single line: the maximum radius, or 00 if passage is impossible. The absolute error from the correct answer must not exceed 10−610^{-6}.

Subtasks

  • Subtask 1 (20 points): 1≤w≤1051\le w\le 10^5; 0≤n≤100\le n\le 10; 0≤xi≤w0\le x_i\le w; −105≤yi≤105-10^5\le y_i\le 10^5; 1≤ri≤1051\le r_i\le 10^5 for every 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤w≤1051\le w\le 10^5; 0≤n≤1000\le n\le 100; 0≤xi≤w0\le x_i\le w; −105≤yi≤105-10^5\le y_i\le 10^5; 1≤ri≤1051\le r_i\le 10^5 for every 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤w≤1051\le w\le 10^5; 0≤n≤10000\le n\le 1000; 0≤xi≤w0\le x_i\le w; −105≤yi≤105-10^5\le y_i\le 10^5; 1≤ri≤1051\le r_i\le 10^5 for every 1≤i≤n1\le i\le n.

Examples

Three sensor layouts

Input

10
2
2 0 3
7 12 4

Output

1.5

Explanation

The corridor has width 1010. The two sensors have centers (2,0)(2,0) and (7,12)(7,12) and radii 33 and 44. The first region meets the left wall, and the second meets the right wall. Their separation is 52+122−3−4=6\sqrt{5^2+12^2}-3-4=6. However, the gap from the second sensor to the left wall is only 7−4=37-4=3. A disk with diameter greater than 33 cannot pass this location; a diameter approaching 33 fits the other gaps. The limiting radius is therefore 3/2=1.53/2=1.5.

Input

10
2
2 0 3
7 8 4

Output

1.216991

Explanation

The sensor radii remain 33 and 44, but the distance between their centers is now 52+82=89\sqrt{5^2+8^2}=\sqrt{89}. The gap between their regions is 89−7≈2.433981\sqrt{89}-7\approx2.433981. The regions meet opposite walls. The clearances to their opposite walls are 55 and 33, both greater than the gap between the two regions. Once this gap closes for the moving disk, a barrier joins the walls. The limiting radius is (89−7)/2≈1.216990566(\sqrt{89}-7)/2\approx1.216990566, printed as 1.216991.

Input

10
2
2 0 3
7 4 4

Output

0

Explanation

The center distance is 52+42=41<7\sqrt{5^2+4^2}=\sqrt{41}<7. The sum of the radii is 77, so the detection regions overlap. The first meets the left wall, and the second meets the right wall. Together they form a barrier across the corridor, preventing passage even for arbitrarily small objects. The answer is 00.