This page is still under construction.

Parts of this page are still being built. What you see may change.

Vampire

Time limit3sMemory limit256 MB

Summary
A circular sun of radius r rises from the horizon behind rectangular buildings, and each dataset asks for the last time the whole disk stays hidden.
Level

Medium6 of 10

Topics
Geometry, Intervals, Sorting
Solved
No attempts yet

Problem

At sunrise the sun is a circle of radius rr. At time t=0t=0 its center is at (0,−r)(0,-r) and it moves upward at speed (0,1)(0,1) per second. Each building is a rectangle sitting on the horizon. Find the last time when the entire sun lies inside the union of the building silhouettes and the region y≤0y \leq 0.

Input

The input has multiple datasets. Each begins with rr and nn, followed by nn lines with xli,xri,hix_{li}, x_{ri}, h_i. The input ends with r=n=0r=n=0.

Output

For each dataset, print the last blocked time tt to four decimal places with absolute error at most 0.0010.001.

Examples1

  1. Example 1

    Input
    2 3
    -2 -1 3
    0 1 3
    2 3 3
    2 2
    -2 0 4
    0 2 3
    2 6
    -3 3 1
    -2 3 2
    -1 3 3
    0 3 4
    1 3 5
    2 3 6
    2 6
    -3 3 1
    -3 2 2
    -3 1 3
    -3 0 4
    -3 -1 5
    -3 -2 6
    0 0
    
    Expected output
    0.0000
    3.0000
    2.2681
    2.2679