This page is still under construction.

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

Data Checker

Interview

Time limit1sMemory limit1024 MB

Summary
Given N circles centered on the x-axis, decide whether every pair is either disjoint or nested, so no two circles intersect.
Level

Medium6 of 10

Topics
Sorting, Intervals, Greedy, Geometry
Solved
No attempts yet

Problem

You have created the problem "Moving Circles 2", and now you must write code that checks whether the data you made satisfies the conditions of that problem.

The data for that problem must satisfy the following conditions.

  1. The center of every circle must lie on the xx-axis.
  2. When any two of the NN circles are chosen, they must not have an intersection point. That is, one circle lies inside the other or outside it.

The data format gives only the number of circles NN, the xx-coordinate of each circle's center, and the radius rr of each circle. Therefore, you only need to check whether condition 2 is satisfied.

Check whether the given data satisfies these conditions.

Input

The first line gives the number of circles NN.

From the second line to the N+1N+1-th line, the xx-coordinate of a circle's center and the radius rr of the circle are given, separated by a space.

Output

If the data satisfies the conditions, print YES. Otherwise, print NO.

Constraints

  • 2≤N≤200,0002 ≤ N ≤ 200,000
  • −1,000,000≤x≤1,000,000-1,000,000 ≤ x ≤ 1,000,000
  • 1≤r≤10,0001 ≤ r ≤ 10,000
  • x,rx, r are integers

Hints

Relative position of two circles

Use the following to determine the relative position of two circles.

Let the radius of circle A be r_Ar\_A, the radius of circle B be r_Br\_B, and the distance between the centers of circles A and B be dd.

They meet at two points.They meet at one point.They do not meet.
Externally tangentInternally tangentExternally separateOne inside the otherConcentric
∥r_A−r_B∥<d<r_A+r_B\|r\_A-r\_B\|<d<r\_A+r\_Br_A+r_B=dr\_A+r\_B=d∥r_A−r_B∥=d\|r\_A-r\_B\|=dr_A+r_B<dr\_A+r\_B<dd<∥r_A−r_B∥d<\|r\_A-r\_B\|d=0d=0

Distance between two points

The formula for the distance dd between (x_1,y_1)(x\_1, y\_1) and (x_2,y_2)(x\_2, y\_2) is as follows.

d=(x_1−x_2)2+(y_1−y_2)2d = \sqrt{(x\_1-x\_2)^2+(y\_1-y\_2)^2}

Examples2

  1. Example 1

    Input
    4
    5 4
    3 1
    6 1
    13 3
    
    Expected output
    YES
    
  2. Example 2

    Input
    4
    3 1
    4 1
    5 1
    6 5
    
    Expected output
    NO