Problem:
 Score : 200 points    Problem Statement In a factory, there are N robots placed on a number line.
Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative.  We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect.
Here, for each i ( 1 \leq i \leq N ), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i , excluding the endpoints.  Find the maximum number of robots that we can keep.      Constraints  1 \leq N \leq 100,000  0 \leq X_i \leq 10^9 ( 1 \leq i \leq N )  1 \leq L_i \leq 10^9 ( 1 \leq i \leq N )  If i \neq j , X_i \neq X_j .  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  X_1  L_1  X_2  L_2  \vdots  X_N  L_N       Output Print the maximum number of robots that we can keep.        Sample Input 1 4
2 4
4 3
9 3
100 5      Sample Output 1 3  By removing Robot 2 , we can keep the other three robots.       Sample Input 2 2
8 20
1 10      Sample Output 2 1       Sample Input 3 5
10 1
2 1
4 1
6 1
8 1      Sample Output 3 5

Solution (Python):

N = int(input())
cnt = 0
L = []
for i in range(N):
    x, l = map(int, input().split())
    L.append([x, l])

L.sort(key=lambda x: x[0])

for i in range(N):
    x, l = L[i]
    if i == 0:
        px, pl = x, l
    else:
        if px + pl >  x - l:
            cnt += 1
            if px + pl > x + l:
                px, pl = x, l
        else:
            px, pl = x, l
print(N - cnt)

Solution (Python):

"""
Created on Sat Jan 18 21:45:18 2020

@author: masat
"""

N = int(input())
end_start_list = []
for i in range(N):
    X, L = map(int, input().split())
    e_s = [X+L, X-L]
    end_start_list.append(e_s)

end_start_list.sort()



e_s_0 = end_start_list[0]
latest_end = e_s_0[0]
counter = 1
for i in end_start_list:
    if i[1] >= latest_end:
        counter += 1
        latest_end = i[0]
    else:
        pass

print(counter)

Solution (Python):
N = int(input())

a_list = []
for i in range(N):
  x, l = map(int, input().split())
  a_list.append([x - l, x + l])
  
b_list = sorted(a_list, key=lambda x:x[0])
cnt = N
start, end = map(int, b_list[0])
for i in range(1,N):
  start_, end_ = map(int, b_list[i])
  if start_ < end:
    if end_ <= end:
      cnt -= 1
      start = start_
      end = end_
      continue
    else:
      cnt -= 1
      continue
  else:
    start = start_
    end = end_
      
      
print(cnt)

Solution (Python):
n=int(input())
r=[]
cnt=1
for i in range(n):
  x,l=map(int,input().split())
  r.append([x+l,x-l])
r.sort()

migi=r[0][0]
for i in range(1,n):
  if r[i][1]>=migi:
    
    cnt+=1
    migi=r[i][0]
print(cnt)

Solution (Python):
from operator import itemgetter
n =int(input())
x =[]
l =[]

for i in range(n):
    x1,l1 = [int(i) for i in input().split()]
    x.append(x1)
    l.append(l1)

min = []
max = []
for i in range(n):
    min1, max1 = (x[i]-l[i],x[i]+l[i])
    min.append(min1)
    max.append(max1)

minmax= sorted([(min[i],max[i])for i in range(n)], key=itemgetter(1))
ans = 0
T = -1000000000
for i in range(n):
    if T<=minmax[i][0]:
        ans +=1
        T = minmax[i][1]
print(ans)

Solution (Python):
n = int(input())
robos = []
for i in range(n):
    x,l = map(int,input().split())
    robos.append([x-l,x+l])

robos.sort(key= lambda x:x[1])

edge = -10000000000000
out = 0
for i in range(n):
    if robos[i][0] >= edge:
        out += 1
        edge = robos[i][1]
    else:
        continue

print(out)

Solution (Python):
import math

N = int(input())

li = []

for i in range(N):
    x, l = map(int, input().split())
    li.append([x-l,x+l])

li.sort(key=lambda x:x[0])
li.sort(key=lambda x:x[1])

ans = 0
t = 0 - 10**9 + 99
for i in range(N):
    if t <= li[i][0]:
        ans += 1
        t = li[i][1]

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
ans = 0
x = [0] * n
for i in range(n):
    x[i] = tuple([int(x) for x in input().strip().split()])

x.sort()
pre = -float('inf')
for xx in x:
    if pre > xx[0] - xx[1]:
        if pre < xx[0] + xx[1]:
            continue
        else:
            pre = xx[0] + xx[1]
            continue
    
    ans += 1
    pre = xx[0] + xx[1]
print(ans)

Solution (Python):

N = int(input())
a =[list(map(int, input().split())) for i in range(N)]

count  = 0

a.sort()

for i in range(N-1):
    right = a[i][0] + a[i][1]
    left = a[i+1][0] - a[i+1][1]
    if right <= left:
        pass
    else:
        count += 1
        if a[i][0] + a[i][1] >= a[i+1][0] + a[i+1][1] and a[i][0] + a[i][1] > a[i+1][0]:
            pass
        else:
            a[i+1][0] = a[i][0]
            a[i+1][1] = a[i][1]
print(N -count)

Solution (Python):
n=int(input())
xl=[list(map(int,input().split())) for i in range(n)]

xl.sort(key=lambda x: x[0])

ans=0
for i in range(1,n):
    if xl[i-1][0]+xl[i-1][1]>xl[i][0]-xl[i][1]:
        ans+=1
        if xl[i-1][0]+xl[i-1][1]<xl[i][0]+xl[i][1]:
            xl[i]=xl[i-1]
print(n-ans)

Solution (Python):
n = int(input())

itv = []
for i in range(n):
  tx,tl = map(int,input().split())  
  itv.append([tx+tl,tx-tl] )

itv = sorted(itv)

ans = 0
right = float('-inf')

for i in range(n):  
  if right <= itv[i][1]:    
    ans += 1
    right = itv[i][0]
    
print(ans)

Solution (Python):
n = int(input())

arm_list = []
for i in range(n):
    array = list(map(int, input().split()))
    a = array[0] - array[1]
    b = array[0] + array[1] - 1
    arm_list.append([a, b])

arm_list.sort(key=lambda x:x[1])

if n == 1:
    print(1)
    exit()
count = 1
a = arm_list[0][1]
b = arm_list[1][0]
for i in range(1, n-1):
    if a < b:
        count += 1
        a = arm_list[i][1]
        b = arm_list[i+1][0]
    else:
        b = arm_list[i+1][0]

if a < b:
    count += 1



print(count)

Solution (Python):
n = int(input())
lr = []
for i in range(n):
    x,l=input().split()
    x=int(x)
    l=int(l)
    lr.append([x-l,x+l])

lr.sort(key=lambda x:x[1])

l = -2000000000
ans=0
for i in range(n):
    if l<=lr[i][0]:
        l=lr[i][1]
        ans+=1

print(ans)

Solution (Python):

N=int(input())
P=[[int(i) for i in input().split()] for  _ in range(N)]
arm=[[p[0]-p[1], p[0]+p[1]] for p in P]
s_arm=sorted(arm, key=lambda x: x[1])


ans = 0
t = -10**9
for i in range(N):
    if (t <= s_arm[i][0]):
        ans+=1
        t = s_arm[i][1]
print(ans)

Solution (Python):


N=int(input())

log=[]
for _ in range(N):
    X,L=map(int,input().split())
    log.append([X,X-L,X+L])
    
log.sort(key=lambda x:x[2])

ans=N
pre=log[0][2]
for i in range(N-1):
    if log[i+1][1]-pre<0:
        
        if log[i+1][2]<pre:
            pre=log[i+1][2]
        ans-=1
    else:
        pre=log[i+1][2]
    
print(ans)

Solution (Python):
n=int(input())
li=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
  li[i].append(li[i][0]-li[i][1])
  li[i].append(li[i][0]+li[i][1])

from operator import itemgetter
li=sorted(li, key=itemgetter(3))

ans=0
now=0

for i in range(n-1):
  if li[now][3]>=li[i+1][3]: 
    ans+=1
    now=i+1
  elif li[now][3]>li[i+1][2]:
    ans+=1
  else:
    now=i+1

print(n-ans)

Solution (Python):
n = int(input());

sf = [ [0]*2 for i in range(n) ];
for i in range(n) :
	xl = input().split(' ');
	sf[i][0] = int(xl[0]) - int(xl[1]);
	sf[i][1] = int(xl[0]) + int(xl[1]);
	

sf.sort(key=lambda x:x[1] );

ans = 1;
end = sf[0][1];
for i in range(1,n) :
	if end <=  sf[i][0] :
		end = sf[i][1];
		ans += 1;

print(ans);

Solution (Python):
n=int(input())
lists=[]
for i  in range(n):
    x,y=map(int,input().split())
    lists.append((x-y,x+y))
lists=sorted(lists,key=lambda x:(x[1]))
A=1
P=lists[0]
for i in range(1,len(lists)):
    if lists[i][0]>=P[1]:
        A+=1
        P=lists[i]
print(A)

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7
n=int(input())
xl=[list(map(int,input().split())) for i in range(n)]
from collections import deque



ans=0
xl.sort()


d=deque(xl)
while d:
    tmp=d.popleft()
    while d:
        if tmp[0]+tmp[1]>d[0][0]-d[0][1]:
            ans+=1
            if tmp[0]+tmp[1]>d[0][0]+d[0][1]:
                
                break
            elif tmp[0]-tmp[1]>d[0][0]-d[0][1]:
                d.popleft()
            else:
                d.popleft()
        else:
            break
if n==1:
    print(1)
    quit()

print(n-ans)

Solution (Python):
f = lambda x, y: (x + y, x - y)
n = int(input())
a = sorted(f(*map(int, input().split())) for _ in range(n))
r = 0
p = -10**9
for x, y in a:
  if y >= p:
    r += 1
    p = x
print(r)

Solution (Python):
N=int(input())
XL=[list(map(int,input().split())) for i in range(N)]

R=[]
for i in range(N):
    a=max(0,XL[i][0]-XL[i][1])
    b=XL[i][1]+XL[i][0]
    R.append([b,a])
R.sort()

ans=0
con_l=0
for i in range(N):
    if con_l <= R[i][1]:
        ans += 1
        con_l = R[i][0]
print(ans)

Solution (Python):
n = int(input())
ra = []
for i in range(n):
    x,l = map(int,input().split())
    ra.append([x-l,x+l])

ra.sort(key = lambda x:x[0])
ans = 1
t = ra[0][1]
for i in range(n):
    if ra[i][0] >= t:
        ans += 1
        t = ra[i][1]
    else:
        t = min(t,ra[i][1])

print(ans)

Solution (Python):
N = int(input())
zahyo = []

for i in range(N):
    A, B = map(int, input().split())
    left = max(A - B, 0)
    right = min(A + B, 1000000000)
    zahyo.append([left,right])
zahyo.sort()

count = 0
prev = [-2,-1]
for now in zahyo:
    if prev[1] >= now[1]:
        prev = now
    elif prev[1] <= now[0]:
        prev = now
        count += 1
print(count)

Solution (Python):
N = int(input())
xl = []
for i in range(N):
  x,l =[int(x) for x in input().split()]
  a = max(x-l,0)
  xl.append([a,x+l])
xl = sorted(xl,key = lambda x:x[1])

minx=xl[0][0]
maxx=xl[0][1]
cnt=0
for i in range(1,N):
  if maxx<=xl[i][0]:
    maxx=xl[i][1]
  else:
    cnt+=1
print(N-cnt)

Solution (Python):
N = int(input())
XL = [tuple(map(int, input().split())) for i in range(N)]

XL.sort(key=lambda x: x[0])

hold = [XL[0]]

ans = 1
for i in range(1, N):
    if hold[-1][0] + hold[-1][1] > XL[i][0] - XL[i][1]:
        if hold[-1][0] + hold[-1][1] < XL[i][0] + XL[i][1]:
            continue
        else:
            hold.append(XL[i])
    else:
        ans += 1
        hold.append(XL[i])

print(ans)

Solution (Python):
N = int(input())
robo = []
for _ in range(N):
    X, L = map(int, input().split())
    left = X - L
    right = X + L
    robo.append((left, right))

robo.sort(key=lambda x: x[1])
right = -10 ** 18
ans = N

for l, r in robo:
    if l < right:
        ans -= 1
        continue
    right = r

print(ans)

Solution (Python):
n = int(input())

robots = []

for _ in range(n):
    x, l = map(int, input().split())
    left, right = x-l, x+l
    robots.append([left, right])

robots.sort()

count = 0
now = -float('INF')

for left, right in robots:
    if left >= now:
        count += 1
        now = right

    else:
        if right < now:
            now = right
        else:
            continue

print(count)

Solution (Python):
import bisect
n=int(input())
p=[[0,0] for i in range(n)]
p[0]=[0,1]
x,l=[],[]
y=[]
for i in range(n):
    tmpx,tmpl=list(map(int,input().split()))
    y.append([tmpx+tmpl,tmpx])
y.sort()
x=[y[i][1] for i in range(n)]
l=[y[i][0]-y[i][1] for i in range(n)]

a=[x[i]+l[i] for i in range(n)]
for i in range(1,n):
    s=bisect.bisect_right(a,x[i]-l[i])
    if s>0:
        p[i]=[max(p[i-1]),max(p[s-1])+1]
    else:
        p[i]=[max(p[i-1]),1]

print(max(p[n-1]))

Solution (Python):
a = int(input())
fanwei = []

for i in range(a):
    one = input().split()
    one = [int(i) for i in one]
    two = [one[0] - one[1], one[0] + one[1]]
    fanwei.append(two)

fanwei = sorted(fanwei, key=lambda student: student[0] + 100000000000000000000 * student[1])

now = -100000000000000000000
ans = 0
for i in fanwei[:]:
    down = i[0]
    if down >= now:
        ans += 1
        now = i[1]


print(ans)

Solution (Python):
N = int(input())

Sn, Tn = [0] * N, [0] * N
XLn = []
for i in range(N):
    x, l = map(int, input().split())
    Sn[i], Tn[i] = x-l, x+l

for i in range(N):
    XLn.append((Tn[i], Sn[i]))

XLn = sorted(XLn, key=lambda x: x[0])

res, t = 0, -float("inf")
for i in range(N):
    if t <= XLn[i][1]:
        res += 1
        t = XLn[i][0]

print(res)

Solution (Python):
import math
def A():
    H = int(input())
    W = int(input())
    N = int(input())
    print(int(min(math.ceil(N/H), math.ceil(N/W))))

def B():
    N = int(input())
    robots = []
    for i in range(N):
        temp = [int(n) for n in input().split()]
        robots.append([temp[0]-temp[1], temp[0]+temp[1]])
    robots.sort(key = lambda x:x[1])
    
    prev_end = robots[0][1]
    count = 1
    for i in range(1, len(robots)):
        cur_start = robots[i][0]
        cur_end = robots[i][1]

        if cur_start >= prev_end:
            
            count += 1
            prev_end = cur_end

    print(count)

def C():
    temp = [int(n) for n in input().split()]
    N = temp[0]
    K = temp[1]
    S = temp[2]
    if S == 10**9:
        ans = [str(S)]*K + [str(S-1)]*(N-K)
    else:
        ans = [str(S)]*K + [str(S+1)]*(N-K)
    print(' '.join(ans))

B()

Solution (Python):
N = int(input())
XL = [list(map(int,input().split())) for i in range(N)]
XL.sort(key=lambda x: x[0]+x[1])
M = XL[0][0]+XL[0][1]-1
ans = 0
for i in range(1,N):
    if M >= XL[i][0]-XL[i][1]:
        ans += 1
    else:
        M = XL[i][0]+XL[i][1]-1
print(N-ans)

Solution (Python):
N = int(input())
xl = []
for i in range(N):
    x,l = map(int,input().split())
    xl.append([x-l,x+l])
xl.sort()
l,r = xl[0]
ans = N
for i in range(1,N):
    l1,r1 = xl[i]
    if l<l1 and r1<r:
        ans -= 1
        l = l1
        r = r1
    elif l1<r:
        ans -= 1
    else:
        l = l1
        r = r1
print(ans)

Solution (Python):
n = int(input())
machine = []
machine_left = []
machine_right = []
for i in range(n):
    x, l = [ int(v) for v in input().split() ]
    machine.append((x-l, x+l))
machine.sort(key = lambda x: x[1])

s = machine[0][1]
ans = 1
for l, r in machine[1:]:
    if l >= s:
        s = r
        ans += 1

print(ans)

Solution (Python):

import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  
  sys.stderr.write(_s+"\n")

n=int(input())

X = [ [] for _ in range(n) ]			
L = [ [] for _ in range(n) ]			
A = [ [] for _ in range(n) ]			


for i in range(n):
	x,l = map(int, input().split())
	X[i],L[i] = x,l
	
	a = x-l
	b = x+l
	
	A[i]=[a,b]


B = sorted(A, key=lambda x: (x[1],-x[0]))







l=B[0][0]
r=B[0][1]
ans=1

for x,y in B:
	if r <= x:
		ans+=1
		l,r=x,y

print(ans)

Solution (Python):
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()

xls = []
for _ in range(n):
    xi, li = na()
    xls.append([xi, li, xi-li, xi+li])
xls.sort(key=lambda x:x[3])


ans = 0
f = -10**10
for i in range(n):
    if f <= xls[i][2]:
        ans += 1
        f = xls[i][3]
print(ans)

Solution (Python):
n = int(input())
arms = [input().split(' ') for _ in range(n)]
for a in arms:
    for i in range(2):
        a[i] = int(a[i])
arms.sort(key=lambda x:x[0])
res = []
for x, l in arms:
    left, right = x - l, x + l
    if not res or res[-1]  <= left:
        res.append(right)
    elif res[-1] > right:
        res[-1] = right
print(len(res))

Solution (Python):
N = int(input()) 

robo_list = []
for i in range(N):
    robo_list.append(list(map(int, input().split())))

robo_list.sort()


xmax = 0
counter = 0
for i in range(N):
    if(i==0):
        robo = robo_list[i]
        xmax = robo[0]+robo[1]
        counter += 1
    else:
        robo = robo_list[i]
        if(robo[0]-robo[1] >= xmax):
            xmax = robo[0]+robo[1]
            counter += 1
        else:
            if(robo[0]+robo[1] <= xmax):
                xmax=robo[0]+robo[1]
                
    
print(counter)

Solution (Python):
n = int(input())
ss = []
for i in range(n):
    x, l = map(int, input().split())
    start = max(0, x-l)
    stop = min(10**9, x + l)
    ss.append([start, stop])

sorted_ss = sorted(ss, key=lambda x: x[1])
ans = 0
t = 0

for i in range(n):
    if t <= sorted_ss[i][0]:
        ans += 1
        t = sorted_ss[i][1]
print(ans)

Solution (Python):
N=int(input())
X=[[0,0]]*N
for i in range(N):
    X[i]=list(map(int,input().split()))
X.sort()
right=X[0][0]+X[0][1]
count=0
for i in range(1,N):
    if right>X[i][0]-X[i][1]:
        count+=1
        right=min(X[i][0]+X[i][1],right)
    else:
        right=X[i][0]+X[i][1]
print(N-count)

Solution (Python):
n = int(input())
li_a = []
for i in range(n):
  a = list(map(int, input().split()))
  li_a.append(a)
li = list(sorted(li_a))
ans = 0
b = li[0][0] + li[0][1]
for i in range(n-1):
  if li[i+1][0] - li[i+1][1] >= b:
    b = li[i+1][0] + li[i+1][1]
  else:
    b = min(b, li[i+1][0]+li[i+1][1])
    ans += 1
print(n-ans)

Solution (Python):
import bisect

N = int(input())
XL = [list(map(int,input().split())) for i in range(N)]
MM = []
for i in range(N):
    MM.append([XL[i][0]-XL[i][1], XL[i][0]+XL[i][1]])


XL = sorted(XL)
MM.sort(key=lambda x: x[0])
MM.sort(key=lambda x: x[1])
ans = 0
now  = -float('inf')
for i in range(N):
    if MM[i][0] >= now:
        ans += 1
        now = MM[i][1]
print(ans)

Solution (Python):
import sys
N = int(input())
input = sys.stdin.readline

R = [None] * N


for i in range(N):
    x, l = list(map(int, input().split()))
    R[i] = (min(l+x, 1000000000), max(x - l, 0))

R.sort()

left = 0

ans = 0

for maximum, minimum in R:
    if left <= minimum:
        ans += 1
        left = maximum

print(ans)

Solution (Python):

n = int(input())
l = []
for i in range(n):
    p,q = map(int,input().split())
    l.append((p+q,p-q))
l.sort()
c = -float('inf')

count = 0

for i in range(n):
    if l[i][1]<c:
        count+=1
    else:
        c = l[i][0]
print(n-count)

Solution (Python):
def main():
    N = int(input())
    X = []
    L = []
    for i in range(N):
        x, l = [int(s) for s in input().split()]
        X.append(x)
        L.append(l)

    ranges = []
    for i in range(N):
        ranges.append((X[i] - L[i], X[i] + L[i]))
    ranges.sort(key=lambda x: x[1])

    cnt = len(ranges)
    end = ranges[0][1]
    for i in range(1, len(ranges)):
        if ranges[i][0] < end:
            cnt -= 1
        else:
            end = ranges[i][1]
    print(cnt)


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
a = []
for _ in range(N):
    x,l = map(int,input().split())
    a.append([x-l,x+l])
a.sort()
ans = 0 
right = -1*1000000000000
for i in a:
    if i[0] >= right:
        ans += 1
        right = i[1]
    else:
        if right > i[1]:
            right = i[1]
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
n=int(input())
xl=[list(map(int,input().split())) for i in range(n)]
ab=[]
for i in range(n):
    x=xl[i][0]
    l=xl[i][1]
    a=x-l
    b=x+l
    ab.append([a,b])
ab.sort(key=lambda x:x[1])
B=-float("inf")
cnt=0
for i in range(n):
    a=ab[i][0]
    b=ab[i][1]
    if a>=B:
        cnt+=1
        B=b
print(cnt)

Solution (Python):
n = int(input())
arr = []
for i in range(n):
	x, l = map(int, input().split())
	r = x+l
	l = x-l
	arr += [[l, r]]
arr.sort()

ma = -888888888
count = 0
for i in range(n):
	if arr[i][0] < ma:
		count += 1
		ma = min(ma, arr[i][1])
	else:
		ma = arr[i][1]
print(n-count)

Solution (Python):
n,*t=map(int,open(0).read().split())
*z,=sorted(zip(*[iter(t)]*2))
s=set()
for i in range(n-1):
    if i in s:
        continue
    x,l=z[i]
    j=i+1
    while 1:
        y,r=z[j]
        if x+l>y-r:
            if y+r<x+l:
                s|={i}
                break
            else:
                s|={j}
        else:
            break
        j+=1
        if j==n:break
print(n-len(s))

Solution (Python):
n = int(input())
lst =[]
for i in range(n):
	a,b = list(map(int, input().split()))
	tmp = []
	tmp.append(a)
	tmp.append(b)
	lst.append(tmp)


rng = []
for j in range(n):
	c = lst[j][0] - lst[j][1]
	d = lst[j][0] + lst[j][1]
	tmp = []
	tmp.append(c)
	tmp.append(d)
	rng.append(tmp)

rng.sort(key=lambda x:x[1])

ct = 1
rngmax = rng[0][1]
nowmin = rng[0][0]
for k in range(1,n):
	nowmin = rng[k][0]
	if nowmin < rngmax:
		continue
	else:
		rngmax = rng[k][1]
		ct += 1
print(ct)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
ab = []
for i in range(n):
    a,b = inpl()
    ab.append((a-b,a+b,b))

ab.sort(key=lambda x:x[1])
res = 1
r = ab[0][1]
for i in range(1,n):
    if ab[i][0] < r:
        continue
    r = ab[i][1]
    res += 1
print(res)

Solution (Python):
N = int(input())
P = []
for i in range(N):
    Xi, Li = map(int, input().split())
    P.append((Xi + Li, Xi - Li))

P.sort()
ans = 0
t = -1000000000
for p in P:
    if p[1] >= t:
        ans += 1
        t = p[0]
print(ans)

Solution (Python):
def main():
    n = int(input())
    rob = []
    for i in range(n):
        rob.append(list(map(int, input().split())))

    x = []
    for i in range(n):
        x.append([rob[i][0] - rob[i][1], rob[i][0] + rob[i][1]])

    x = sorted(x, key=lambda y:y[1])

    x_now = x[0][0]
    count = 0
    j = 0

    while j < n:
        for i in range(j, n):
            if x_now <= x[i][0]:
                x_now = x[i][1]
                count += 1
                j = i
                break
            else:
                j += 1

    print(count)


if __name__ == '__main__':
    main()

Solution (Python):



def main():
    n = int(input())
    y = list()

    for i in range(n):
        xi, li = map(int, input().split())
        
        y.append((xi - li, xi + li))

    count = 1
    sorted_y = sorted(y, key=lambda x: x[1])
    end_point = sorted_y[0][1]

    for left, right in sorted_y[1:]:
        if left >= end_point:
            end_point = right
            count += 1

    print(count)


if __name__ == '__main__':
    main()

Solution (Python):

from operator import itemgetter
n = int(input())
xl = [list(map(int, input().split())) for _ in range(n)]
lr = sorted([[xl[i][0]-xl[i][1],xl[i][0]+xl[i][1]] for i in range(n)], key=itemgetter(1,0))

cnt = 1
cl = lr[0][0]
cr = lr[0][1]
for l,r in lr[1:]:
    if cr<=l:
        cr = r
        cl = l
        cnt += 1

print(cnt)

Solution (Python):
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')

N=int(input())


l=[]

for i in range(N):
	a,b=map(int,input().split())
	st,fin=(a-b,a+b)
	l.append([fin,st])


list=sorted(l)

pt=list[0][0]
cnt=1


for j in range(1,N):
	if pt<= list[j][1]:
		cnt+=1
		pt=list[j][0]

print(cnt)

Solution (Python):
n=int(input())
AB=[]
for i in range(n):
    x,l=map(int,input().split())
    a=x-l
    b=x+l
    AB.append((a,b))
cnt=1
AB.sort(key=lambda L:L[0],reverse=True)
simekiri=AB[0][0]
for i in range(1,n):
    migi=AB[i][1]
    hidari=AB[i][0]
    if migi<=simekiri:
        cnt+=1
        simekiri=hidari
print(cnt)

Solution (Python):
n = int(input())
x = [[0,0] for i in range(n)]
for i in range(n):
    x[i][0] , x[i][1] = map(int,input().split())

x.sort()
cnt = 0
i = 0
while i < len(x)-1:
    if x[i][0] + x[i][1] > x[i+1][0] - x[i+1][1]:
        if x[i][0] + x[i][1] > x[i+1][0] + x[i+1][1]:
            del x[i]
        else:
            del x[i+1]
    else:
        i += 1

print(len(x))

Solution (Python):

import sys


def solve(N: int, X: "List[int]", L: "List[int]"):
    d = {}
    for i in range(N):
        d[X[i]]=L[i]

    d=sorted(d.items())


    toru1=0
    maeR=d[0][0]+d[0][1]
    for i in range(1,N):
        tsugiL=d[i][0]-d[i][1]
        if maeR>tsugiL:
            tsugiR=d[i][0]+d[i][1]
            toru1+=1
            if tsugiR<maeR:
                maeR=tsugiR
        else:
            maeR=d[i][0]+d[i][1]

    toru2=0
    maeL=d[N-1][0]-d[N-1][1]
    for i in reversed(range(N-1)):
        tsugiR=d[i][0]+d[i][1]
        if maeL<tsugiR:
            tsugiL=d[i][0]-d[i][1]
            toru2+=1
            if tsugiL<maeR:
                maeR=tsugiL
            toru2+=1
        else:
            maeL=d[i][0]-d[i][1]

    print(N-min(toru1,toru2))
    
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    X = [int()] * (N)  
    L = [int()] * (N)  
    for i in range(N):
        X[i] = int(next(tokens))
        L[i] = int(next(tokens))
    solve(N, X, L)

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
XL = [tuple(map(int, input().split())) for _ in range(N)]

rnl = [(X + L, L - X) for X, L in XL]
rnl.sort()

ans = 0
cur_max = -float("inf")

for r, nl in rnl:
    l = -nl
    if l >= cur_max:
        ans += 1
        cur_max = r

print(ans)

Solution (Python):
N = int(input())
if N==1:
    print(1)
    exit()
segs = [[0,0]]*N

X = [0]*N
L = [0]*N
for i in range(N):
    X[i],L[i] = map(int,input().split())

for i in range(N):
    segs[i] = [X[i]-L[i],X[i]+L[i]]
segs.sort(reverse=True, key=lambda x:x[0])

ans=0
seg = segs.pop()

    

while len(segs)!=0:
    seg2 = segs.pop()
    if len(segs)==0:
        ans += 1
    if seg[1]>seg2[0]:
        if seg[1]<=seg2[1]:
            continue
        else:
            seg=seg2
    else:
        ans+=1
        seg=seg2
        

print(ans)

Solution (Python):

N = int(input())

robots = []
for i in range(N):
    X,L = list(map(int,input().split()))
    robots.append((X-L,X+L))

robots.sort(key=lambda x:x[1])

point = -(10**9)
ans = 0
for i in range(N):
    if point <= robots[i][0]:
        ans += 1
        point = robots[i][1]

print(ans)

Solution (Python):
rl = []
N = int(input())
for i in range(N):
    x, l = map(int, input().split())
    rl.append((x+l, x-l))
rl.sort()

ans = 0
tmp = rl[0][0]
for i in range(N):
    if i and rl[i][1] < tmp:
        continue
    tmp = rl[i][0]
    ans += 1
print(ans)

Solution (Python):
n = int(input())
xl_lis = [list(map(int,input().split())) for i in range(n)]
tempx = -(10**10)
ans = 0
xl_lis.sort()

for i in range(n):
    if tempx > xl_lis[i][0] - xl_lis[i][1] and tempx < xl_lis[i][0] + xl_lis[i][1]:
        ans += 1
    
    elif tempx > xl_lis[i][0] - xl_lis[i][1] and tempx >= xl_lis[i][0] + xl_lis[i][1]:
        ans += 1
        tempx = xl_lis[i][0] + xl_lis[i][1]
    else:
        tempx = xl_lis[i][0] + xl_lis[i][1]
print(n-ans)

Solution (Python):
n=int(input())
XL=[]
for _ in range(n):
    XL.append(list(map(int,input().split())))
XL.sort()
ans=n
right=XL[0][0]+XL[0][1]
for i in range(n-1):
    if right<=XL[i+1][0]-XL[i+1][1]:
        right=XL[i+1][0]+XL[i+1][1]
    else:
        if right<=XL[i+1][0]+XL[i+1][1]:
            ans-=1
        else:
            ans-=1
            right=XL[i+1][0]+XL[i+1][1]
print(ans)

Solution (Python):
N = int(input())
XL = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    XL.append(array)
XL = sorted(XL)
Y = 0
cnt = 0
for i in range(N):
    if max(XL[i][0]-XL[i][1],0)>=Y:
        cnt += 1
        Y = XL[i][0]+XL[i][1]
    else:
        Y = min(Y,XL[i][0]+XL[i][1])
print(cnt)

Solution (Python):
n=int(input())
robots=[]
for i in range(n):
    x,l=map(int,input().split())
    robots.append([x-l,x+l])

robots.sort(key=lambda x:x[1])
now_d=-9999999999999999999
ans=0
for ri in robots:
    if(now_d<=ri[0]):
        ans+=1
        now_d=ri[1]
print(ans)

Solution (Python):
N = int(input())

lob = []

for _ in range(N):
    X, L = map(int,input().split())
    lob.append([X + L, X - L])

lob.sort()

ans = 0
last = (-1) * 10 ** 9 - 1
for l in lob:
    if last <= l[1]:
        ans += 1
        last = l[0]

print(ans)

Solution (Python):
from operator import itemgetter
n = int(input())
lst1 = []
for i in range(n):
    x,l = map(int,input().split())
    lst1.append([x-l,x+l])

lst1.sort(key=itemgetter(1)) 

ans = 1
start = lst1[0][1]

for i in range(1,n):
    if lst1[i][0] >= start:
        start = lst1[i][1]
        ans += 1

print(ans)

Solution (Python):
n = int(input())


def convert(l):
    x, arm = l
    return [x-arm, x+arm]


L = [convert(list(map(int, input().split()))) for _ in range(n)]
L.sort(key=lambda x:x[0])


last = -10**9-1
count = 0
for ind, elm in enumerate(L):
    
    if elm[0] >= last:
        last = elm[1]
        count += 1
    elif elm[1] < last:
        last = elm[1]
    else:
        pass

print(count)

Solution (Python):
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0

n=I()
a=[]
for i in range(n):
    x,l=LI()
    a.append((x,l,x+l))

a.sort(key=lambda x:x[2])

R=-inf
for i in range(n):
    x,l,r=a[i]
    if x-l>=R:
        ans+=1
        R=r
    
    
    
print(ans)

Solution (Python):
n=int(input())
l=[]
for i in range(n):
    a,b=map(int,input().split())
    l.append((a-b,i,0))
    l.append((a+b-0.1,i,1))
l.sort()
buf=0
b=0
count=0
for i in range(2*n):
    if l[i][2]==0:
        buf=buf | 1<<l[i][1]
        b+=1
    elif l[i][2]==1 and (buf & (1<< l[i][1]))>>l[i][1]==1:
        count+=1
        buf=0
        b=0
    
print(count)