This page is still under construction.

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

Undetected Route

Time limit2sMemory limit256 MB

Summary
Find how many leading sensors can stay active before their overlapping circles join the left and right walls and block travel from the bottom edge to the top.
Level

Medium6 of 10

Topics
Union-find, Binary search, Graph, Geometry
Solved
No attempts yet

Problem

The Department of Defense has been designing autonomous robots that infiltrate war zones and other hostile places to carry out missions. It now wants to test the latest design, the Penetrator1700, and you are designing the test environment.

The test environment is a rectangular field with sensors placed inside it. Each sensor has a radius that defines the region where it detects a robot. You want the field to hold as many sensors as possible while a route across the field that avoids detection still exists.

The field is the region of the coordinate plane with 0≤x≤2000 \le x \le 200 and 0≤y≤3000 \le y \le 300. The robot is a point that stays on the field at all times. It starts on the bottom edge (y=0y = 0), must finish on the top edge (y=300y = 300), and must never come within range of a sensor. There are NN sensors, each given by three integers (x,y,r)(x, y, r), where (x,y)(x, y) is a point on the field and rr is its radius of detection. The sensor circles may overlap, but no circle is tangent to another circle or to the boundary of the field. All sensors start inactive. Find the largest kk such that the robot has a route across the field when sensors 1,2,3,…,k1, 2, 3, \ldots, k are active, and no route once sensor k+1k+1 is active as well. Activating all NN sensors is guaranteed to leave no route.

Sensor circles

Figure: the sensor circles of the first three examples.

Input

The first line holds a positive integer NN (N≤200N \le 200). Each of the next NN lines holds three space separated integers xx, yy, rr for one sensor, with r≤300r \le 300. All sensors sit at different (x,y)(x, y) positions.

Output

Print a single integer, the largest kk described above. It may be 00.

Examples4

  1. Example 1

    Input
    6
    36 228 58
    164 224 58
    88 170 42
    93 105 42
    167 85 58
    28 44 58
    
    Expected output
    2
    
  2. Example 2

    Input
    6
    36 228 58
    28 44 58
    164 224 58
    88 170 42
    93 105 42
    167 85 58
    
    Expected output
    3
    
  3. Example 3

    Input
    6
    28 44 58
    36 228 58
    88 170 42
    93 105 42
    164 224 58
    167 85 58
    
    Expected output
    4
    
  4. Example 4

    Input
    3
    100 150 101
    30 30 10
    170 30 100
    
    Expected output
    0