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



Sample input:
4
2 4
4 3
9 3
100 5


Sample output:
3

Submission status: Accepted

Solution code:
N = int(input())
rob = [] 

for i in range(N):
    x, l = map(int,input().split())
    t = x + l
    rob.append((t,x,l))

rob.sort()
Max = -float("inf")
ans = 0
for i in range(len(rob)): 
    t = rob[i][0]
    x = rob[i][1]
    l = rob[i][2]
    if x-l < Max:
        continue
    else:
        ans += 1
        Max = t
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

n = int(input().rstrip())
x_list = []
l_list = []
start_end_list = []

for i in range(n):
    xi, li = map(int, input().split())
    x_list.append(xi)
    l_list.append(li)

    start = xi - li
    if start < 0:
        start = 0
    end = xi + li

    start_end_list.append([start, end])

# endでソートする。二次元配列の二つ目の要素でソートする
# sortメソッドでラムダ式を使う
start_end_list.sort(key=lambda x: x[1])

past_end = 0
remain_machine = 0
for st_en in start_end_list:
    start, end = st_en
    if start >= past_end:
        past_end = end
        remain_machine += 1

print(remain_machine)

Submission status: Accepted

Solution code:
n = int(input())
dat = []
for _ in range(n):
    x, l =map(int, input().split())
    dat.append([x-l, x+l])
dat.sort(key=lambda x: x[1])
#print(dat)
prevr = -99999999999999999
res = 0
for i in range(n):
    if dat[i][0] >= prevr:
        prevr = dat[i][1]
        res += 1
print(res)

Submission status: Accepted

Solution code:
n = int(input())

xl = [list(map(int, input().split())) for _ in range(n)]

# 計算しやすいように区間を出しておく
position = [(xl[i][0]-xl[i][1],xl[i][0]+xl[i][1]) for i in range(n)]
position = sorted(position, key=lambda x: x[1])

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

# 全ロボットを見る
for pos in position:
    # 腕が交わらない場合
    if  min_arm <= pos[0]:
        ans += 1
        min_arm = pos[1]
print(ans)

Submission status: Accepted

Solution code:
def m():
    N = int(input())
    XL = [list(map(int, input().split())) for _ in range(N)]
    ST = [[xl[0] - xl[1], xl[0] + xl[1]] for xl in XL]
    ST.sort(key=lambda x: x[1])
    ans = 1
    right = ST[0][1]
    for i in range(1, N):
        if right <= ST[i][0]:
            right = ST[i][1]
            ans += 1
    return ans


print(m())

Submission status: Accepted

Solution code:
import sys
#import numpy as np
import math
#from fractions import Fraction
#import itertools
#from collections import deque
#import heapq
#from fractions  import gcd
input=sys.stdin.readline
n=int(input())
xl=[list(map(int,input().split())) for _ in range(n)]
xl.sort(key=lambda x:x[0])
xb=xl[0][0]
lb=xl[0][1]
c=0
for i in range(1,n):
    x=xl[i][0]
    l=xl[i][1]
    if x-l<xb+lb:
        c+=1
        if x+l<xb+lb:
            xb=x
            lb=l
    else:
        xb=x
        lb=l
print(n-c)

Submission status: Accepted

Solution code:
N = int(input())
l = []

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

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

start = l[0][1]
ans = 1
for i in range(1,N):
    if start <= l[i][0]:
        start = l[i][1]
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())

sg = []

for i in range(n):
    x, l = map(int, input().split())
    sg.append([max(x - l, 0), x + l])

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

prev = sg[0][1]

ans = 0
for i in range(1, n):
    if prev > sg[i][0]:
        ans += 1
    else:
        prev = sg[i][1]

print(n - ans)

Submission status: Accepted

Solution code:
N = int(input())
l = []

for _ in range(N):
    a, b =map(int, input().split())
    l.append((a-b, a+b))

l = sorted(l, key=lambda x:x[1])
start = l[0][1]
ans = 1

for i in range(1, N):
    # print(f"start{start}, ")
    if start <= l[i][0]:
        ans += 1
        start = l[i][1]
print(ans)

Submission status: Accepted

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

sorted_lst = sorted(lst)
num = 0
ans = n
while True:
    tmp = sorted_lst[num][0]
    for i in range(num + 1, n):
        if tmp > sorted_lst[i][1]:
            ans -= 1
        else:
            num = i
            break
        if i == n - 1:
            num = i
            break
    if num == n - 1:
        break

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
array = [list(map(int, input().split())) for i in range(N)]
for line in array:
    line.append(line[0] - line[1])
    line.append(line[0] + line[1])
array = sorted(array, key=lambda x: x[3])

count = 0
max_r = -float('inf')
for i in range(N):
    current = array[i]
    if current[2] >= max_r:
        count += 1
        max_r = current[3]
print(count)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)


def test(array, index, last_position, count, min_count):
    # 除去数が多いパターンは破棄する
    if min_count[0] != -1 and count >= min_count[0]:
        return
    if index + 1 == len(array):
        # print("count:{}".format(count))
        min_count[0] = count if min_count[0] == - \
            1 or count < min_count[0] else min_count[0]
        return
    current = array[index]

    # 前のと手がぶつかる場合は取り除く
    if last_position >= current[2]:
        test(array, index + 1, last_position, count + 1, min_count)
    # 前のとぶつからない場合は取り除かないパターンも
    else:
        test(array, index + 1, index, count, min_count)


N = int(input())
array = [list(map(int, input().split())) for i in range(N)]
for line in array:
    line.append(line[0] - line[1])
    line.append(line[0] + line[1])
array = sorted(array, key=lambda x: x[3])

count = 0
max_r = -float('inf')
for i in range(N):
    current = array[i]
    # print(max_r)
    # print(current[2])
    if current[2] >= max_r:
        # print("残す")
        count += 1
        max_r = current[3]
# test(array, 0, -1, 0, min_count)
print(count)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3


def main():
    N = int(input())
    X = [None] * N
    for i in range(N):
        x, l = map(int, input().split())
        X[i] = (x+l,x-l)
    X.sort()
    ans = 0
    maxT = - 10**18
    for i in range(N):
        if maxT <= X[i][1]:
            ans += 1
            maxT = X[i][0]
    print(ans) 


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys,bisect

input=sys.stdin.readline

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

robot.sort()
pos=[robot[i][0] for i in range(N)]
arm=[-1]*N
for i in range(0,N):
    index=bisect.bisect_right(pos,robot[i][0]-2*robot[i][1])
    arm[i]=index-1

dp=[0]*N
dp[0]=1
Max=[0]*N
Max[0]=1
for i in range(1,N):
    if arm[i]==-1:
        dp[i]=1
    else:
        dp[i]=1+Max[arm[i]]
    Max[i]=max(dp[i],Max[i-1])

print(max(dp))

Submission status: Accepted

Solution code:
n = int(input())

Robo = []
for i in range(n):
    x, l = map(int, input().split())
    Robo.append([x-l, x+l])
Robo.sort(key=lambda x: x[1])

#print(Robo)
biggest_right = 2 * -10**9 - 1
counter = 0
for left, right in Robo:
    if biggest_right <= left:
        counter += 1
        biggest_right = max(right, biggest_right)
print(counter)

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    xl=[0]*n
    for i in range(n):
        xl[i]=list(map(int,readline().split()))

    a=[[0,0] for _ in range(n)]
    for i in range(n):
        a[i][0]=xl[i][0]-xl[i][1]
        a[i][1]=xl[i][0]+xl[i][1]
    a.sort(key=lambda x:x[1])
    s=a[0][1]
    
    ans=1
    for i in range(1,n):
        if s<=a[i][0]:
            ans+=1
            s=a[i][1]

    print(ans)
    
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする


def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N=len(v)
    size=len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    s = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    l=[(s[i][0]+s[i][1],s[i][0]-s[i][1]) for i in range(N)]
    l.sort()

    cur=l[0][0]
    ans=1
    for rob in l[1:]:
        if cur>rob[1]:
            continue
        ans+=1
        cur=rob[0]
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N=int(input())
XL=sorted([list(map(int,input().split())) for i in range(N)],key=lambda x:x[0]+x[1])
count=0
left=-10**9
for x,l in XL:
    if left<=x-l:
        count+=1
        left=x+l
print(count)

Submission status: Accepted

Solution code:
N=int(input())
XL=sorted([list(map(int,input().split())) for i in range(N)],key=sum)
count=0
left=-10**9
for x,l in XL:
    if left<=x-l:
        count+=1
        left=x+l
print(count)

Submission status: Accepted

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

# 区間スケジューリング問題
# 区間の集合の中から、重ならないように最大で何個選べるかを問う問題である。
# 区間を「終端が早い順」にソートして、とれる順にとる Greedy で解くことができる。
# XL<-区間の集合

def main():
    N = int(input())
    XL = [None] * N
    for n in range(N):
        X, L = map(int,input().split())
        XL[n] = (X-L,X+L)
    XL.sort(key=lambda x:x[1])
    ret = 0
    TMP = XL[0][0]
    for x in XL:
        if TMP <= x[0]:
            TMP = x[1]
            ret += 1
    print(ret)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
robo_range = []
for _ in range(N):
  X, L = map(int,input().rstrip().split())
  robo_range.append((X-L,X+L))
robo_range_sort = sorted(robo_range,key = lambda x:x[1])
ans = 0
cut = -float('inf')
for i in range(N):
  if cut <= robo_range_sort[i][0]:
    ans += 1
    cut = robo_range_sort[i][1]
print(ans)

Submission status: Accepted

Solution code:
M,a=-float("inf"),0
for X,L in sorted([list(map(int,a.split()))for a in open(0)][1:],key=sum):
 if M<=X-L:a+=1;M=X+L
print(a)

Submission status: Accepted

Solution code:
M,a=-float("inf"),0
for X,L in sorted(zip(*[iter(map(int,open(0).read().split()[1:]))]*2),key=sum):
 l,r=X-L,X+L
 if M<=l:a+=1;M=r
print(a)

Submission status: Accepted

Solution code:
M,a =-float("inf"),0
for X,L in sorted(zip(*[iter(map(int,open(0).read().split()[1:]))]*2),key=sum):
 l,r=X-L,X+L
 if M<=l:a+=1;M=r
print(a)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
INF = float("inf")
n, *d = map(int, open(0).read().split())
p = sorted(zip(*[iter(d)]*2), key=sum)
M, a = -INF, 0
for X, L in p:
    l, r = X-L, X+L
    if M <= l:
        a += 1
        M = r
print(a)

Submission status: Accepted

Solution code:
N=int(input())
arms=[list(map(int,input().split())) for _ in range(N)]
points=[]
for i in range(N):
    points.append([arms[i][0]-arms[i][1],arms[i][0]+arms[i][1]])
#print(points)
points.sort(key=lambda x:x[1])
#print(points)
nowr=-float("inf")
cnt=0
for i in points:
    l,r=i
    if nowr<=l:
        nowr=r
        cnt=cnt+1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
line = []
for _ in range(n):
    x, l = map(int, input().split())
    s, g = x-l, x+l
    line.append([g, s])

line.sort()
ans = 1
now_g = line[0][0]

for g, s in line[1:]:
    if now_g <= s:
        ans += 1
        now_g = g

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
xl=[list(map(int,input().split())) for _ in range(n)]
lr=[[xl[i][0]-xl[i][1],xl[i][0]+xl[i][1]] for i in range(n)]
lr.sort(key=lambda x:x[1])
ans=n
r=lr[0][1]
for i in range(1,n):
  if lr[i][0]<r:
    ans-=1
  else:
    r=lr[i][1]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

R = []

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

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

ans = 0
right = -10**9 - 1
i = 0
while(i < N):
    left = R_sorted[i][0]
    if left >= right:
        ans += 1
        right = R_sorted[i][1]
    i += 1

print(ans)

Submission status: Accepted

Solution code:
from operator import itemgetter

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

l.sort(key = itemgetter(1))
cnt = 0
s = - 10 ** 10
for i in range(N):
  if l[i][0] >= s:
    s = l[i][1]
  else:
    cnt += 1
print(N-cnt)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
info = [0] * n
for i in range(n):
    x, l = map(int, input().split())
    info[i] = [x+l, x, l]

info.sort()
ans = 1
right = info[0][1] + info[0][2]
for i in range(1, n):
    if right <= info[i][1] - info[i][2]:
        ans += 1
        right = info[i][1] + info[i][2]
print(ans)

Submission status: Accepted

Solution code:
import sys
n = int(input())
info = [0] * n
for i in range(n):
    x, l = map(int, input().split())
    info[i] = [x+l, x, l]

info.sort()
ans = 1
right = info[0][1] + info[0][2]
for i in range(1, n):
    if right <= info[i][1] - info[i][2]:
        ans += 1
        right = info[i][1] + info[i][2]
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
L=[]
for i in range(N):
    x,l=map(int,input().split())
    a,b=x-l,x+l
    L.append((a,b))
L.sort(key=lambda  ab: ab[1])
#print(L)
robot=1
b=L[0][1]
for i in range(1,N):
    A,B=L[i]
    if A>=b:
        robot+=1
        b=B
print(robot)

Submission status: Accepted

Solution code:
N = int(input())
ABs = []
for i in range(N):
  X, L = map(int, input().split())
  A, B = X-L, X+L
  ABs.append((A, B))
ABs.sort(key=lambda AB: AB[1])
#print(ABs)
r = 1
b = ABs[0][1]
for i in range(1, N):
  A, B = ABs[i]
  if A >= b:
    r += 1
    b = B
print(r)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N = ii()
XL = li2(N)
R = dp2(0, 2, N)

for i in range(N):
    R[i][0] = XL[i][0] - XL[i][1]
    R[i][1] = XL[i][0] + XL[i][1]


R = sorted(R, key=lambda x:x[1])
m = -float('inf')
cnt = 0
for i in range(N):
    if R[i][0] >= m:
        cnt += 1
        m = R[i][1]

print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
lls = []
rls = []
sels = []
for _ in range(N):
    x,l = map(int, input().split())
    lls.append(x-l)
    rls.append(x+l)
    sels.append([x-l,x+l])

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

start = -float('inf')

ans = 0
for item in sels:
    if start <= item[0]:
        ans += 1
        start = item[1]

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

def main():
    N = int(input())
    robots = []
    for _ in range(N):
        x,l = [int(x) for x in input().split()]
        robots.append((x-l, x+l))

    # print(sorted(robots.items(), key=lambda x:x[1]))
    cnt = 0
    t = -float('inf')
    for start,end in sorted(robots, key=lambda x:x[1]):
        # print(t,start)
        if t <= start:
            # print('append')
            cnt += 1
            t = end
    print(cnt)
        

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

N = int(input().split()[0])
xlt_list = []

for _ in range(N):
    x, l = list(map(int, input().split()))
    xlt_list.append((x, l, x + l))

xlt_list = sorted(xlt_list, key=lambda x: x[2])
count = 0
before_t = -float("inf")
for i, xlt in enumerate(xlt_list):
    x, l, t = xlt
    if x - l >= before_t:
        count += 1
        before_t = t

ans = count
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
X = np.zeros([N,4], dtype=int)

for i in range(N):
    X[i,0], X[i,1] = map(int, input().split())
    X[i,2], X[i,3] = X[i,0] - X[i,1], X[i,0] + X[i,1]    

col_num = 3
X = X[np.argsort(X[:, col_num])]
cnt = 1
r_min = X[0,3]
for i in range(1,N):
    if X[i,2] >= r_min:
        cnt += 1
        r_min = X[i,3]
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
xl = [list(map(int, input().split())) for _ in range(N)]

xl.sort()

ans = N
rpre = xl[0][0] + xl[0][1]

for x, l in xl[1:]:
    ll = max(x - l, 0)
    rr = x + l
    if ll < rpre:
        ans -= 1
        if rr < rpre: rpre = rr
    else:
        rpre = rr

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
xl = [list(map(int, input().split())) for _ in range(n)]
robot = []

for v in xl:
    robot.append([v[0]-v[1], v[0]+v[1]])
robot.sort(key=lambda x:x[1])

prev = 0
cnt = 0
for i in range(1, n):
    if robot[prev][1] > robot[i][0]:
        cnt += 1
    else:
        prev = i
print(n-cnt)

Submission status: Accepted

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial#, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    n = i_input()
    num_list = []
    for _ in range(n):
        x, l = i_map()
        left = x - l
        right = x + l
        tmp = [right, left]
        num_list.append(tmp)

    num_list.sort()

    ans = 0
    max_right = -INF

    for i in range(n):
        right, left = num_list[i]
        if max_right <= left:
            ans += 1
            max_right = right

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
arms = []
ans = 1
for i in range(N):
    X,L = (int(x) for x in input().split())
    arms.append((X-L,X+L))
arms.sort(key=lambda x:x[1])
limit = arms[0][1]
for x in arms[1:]:
    if x[0] < limit:
        continue
    else:
        limit = x[1]
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import heapq
from sys import stdin
input = stdin.readline

#入力
# s = input()
n = int(input())
# n,m = map(int, input().split())
# a = list(map(int,input().split()))
# a = [int(input()) for i in range()]


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


def main():
    p = []
    for x,l in xl:
        p.append([x-l,x+l])
    p = sorted(p, key=lambda x:x[1])

    ans = 0
    mx = -10**10
    for st in p:
        s,t = st[0],st[1]
        if s>=mx:
            ans+=1
            mx=t
    print(ans)



    
    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline
from operator import itemgetter

def main():
    N = int(input())
    arm = []
    for _ in range(N):
        x,l = map(int,input().split())
        arm.append((x-l,x+l))
    
    count = 0
    arm.sort(key=itemgetter(1))
    
    right = -10**10
    for l,r in arm:
        if right <= l:
            right = r
            count += 1
    
    print(count)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
_, *_XL = open(0).read().split()

XL = list(zip(*[map(int, iter(_XL))]*2))

ans = 0
t = -10**10 # 数直線のマイナス方向からスタートする

arms = [(X-L, X+L) for X, L in XL]
arms_sorted = sorted(arms, key=lambda k:k[1])

ans = 0

for s, e in arms_sorted:
    if t <= s:
        t = e
        ans += 1
        
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
R = sorted([list(map(int, input().split())) for i in range(N)])
T = []
for i in range(N):
    T.append([R[i][0] + R[i][1], R[i][0] - R[i][1]])
T.sort(reverse=True)
while len(T) - 1 > 0:
    t = T.pop()
    i = 1
    while len(T) and t[0] > T[-1][1]:
        N -= 1
        i += 1
        T.pop()
print(N)

Submission status: Accepted

Solution code:
N = int(input())
X = [list(map(int, input().split())) for i in range(N)]
LR = [[x[0]-x[1], x[0] + x[1]] for x in X]
LR.sort(key=lambda x:x[1])

A = 1
right = LR[0][1]
for i in range(1, N):
    if right <= LR[i][0]:
        A += 1
        right = LR[i][1]
print(A)

Submission status: Accepted

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N = int(input())
    XL = [None] * N
    for n in range(N):
        X, L = map(int,input().split())
        XL[n] = [X-L,X+L]
    XL.sort(key=lambda x:x[1])
    ret = 1
    TMP = XL[0][1]
    for x in XL[1:]:
        if TMP<=x[0]:
            TMP = x[1]
            ret += 1
    print(ret)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from operator import itemgetter
n=int(input())
xl=[list(map(int,input().split()))for i in range(n)]
R=[(xl[i][0]-xl[i][1],xl[i][0]+xl[i][1]) for i in range(n)]
r=sorted([(R[i][0],R[i][1]) for i in range(n)],key=itemgetter(1))
s=r[0][1]
ans=1
for i in range(n-1):
    if r[i+1][0]>=s:
        s=r[i+1][1]
        ans+=1
print(ans)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
k=[[0,0] for i in range(n)]
for i in range(n):
    a,l=map(int,input().split())
    left=a-l
    right=a+l
    k[i][0]=left
    k[i][1]=right
k.sort(key=lambda x:x[1])
tmp=k[0][1]
ans=1
for i in range(n):
    if k[i][0]>=tmp:
        tmp=k[i][1]
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
xl = []
for i in range(n):
    x,l = map(int,input().split())
    xl.append([x-l,x+l])
xl.sort(key = lambda x: x[1])
ans = 0
arm = -10**18
for i in range(n):
    if arm<=xl[i][0]:
        ans += 1
        arm = xl[i][1]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
X = []
for _ in range(n):
    x, l = map(int, input().split())
    X.append((x - l, x + l))

count = 0
current = -1 * float('inf')
for x in sorted(X, key=lambda x: x[1]):
    if x[0] >= current:
        count += 1
        current = x[1]
print(count)

Submission status: Accepted

Solution code:
n = int(input())
robots = [tuple(map(int,input().split())) for _ in range(n)]
#
robots =[(x+l,x-l) for x,l in robots]
#
robots.sort()
#
cnt = 0
last = -float('inf')
for r,l in robots:
    if last <= l:
        cnt += 1
        last = r
print(cnt)

Submission status: Accepted

Solution code:
import sys
from collections import deque, Counter, defaultdict
from itertools import permutations
import heapq


def resolve():
    N = int(sys.stdin.readline().strip())
    pq = []
    for _ in range(N):
        X, L = map(int, sys.stdin.readline().strip().split())
        heapq.heappush(pq, (X + L, X - L))
    ans = 0
    while pq:
        ans += 1
        right, _ = heapq.heappop(pq)
        if pq:
            _, next_left = pq[0]
            while next_left < right:
                heapq.heappop(pq)
                if not pq:
                    break
                _, next_left = pq[0]

    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n=int(input())
l=sorted([list(map(int,input().split())) for i in range(n)],key=lambda x:x[0]-x[1],reverse=1)
now=float("INF")
ans=0
for i in l:
    if sum(i)<=now:
        now=i[0]-i[1]
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
import sys
l=[i.rstrip().split() for i in sys.stdin.readlines()]
l=[list(map(int,i)) for i in l]
l=[[i-j,i+j] for i,j in l]
from operator import itemgetter
l.sort(key=itemgetter(1))
ans=N
end=l[0][1]
for i in range(N-1):
   if l[i+1][0] < end:
      ans-=1
   else:
      end=l[i+1][1]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
xl = [list(map(int, input().split())) for i in range(n)]
l = [[i[0] + i[1], i[0] - i[1]] for i in xl]
l.sort(key=lambda x:x[0])
ans = 0
m = 10 ** 9 * -1
for i in range(n):
    if m <= l[i][1]:
        ans += 1
        m = l[i][0]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ST = []
for i in range(N):
    x, l = list(map(int, input().split()))
    ST.append([x-l, x+l])
ST.sort(key = lambda x :x[1])
startT = ST[0][1]
ans = 1
if N != 1:
    for i in range(1,N):
        if startT <= ST[i][0]:
            startT = ST[i][1]
            ans += 1
            
print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    L = []
    for i in range(N):
        xi, li = map(int, input().split())
        s = xi - li
        f = xi + li
        L.append((f, s))
    
    L.sort()

    ans = 0
    finish = -float("inf")
    for i in L:
        if finish <= i[1]:
            ans += 1
            finish = i[0] 

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())

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

robots.sort()

ans = n
n_r = robots[0][0]
for i in range(1, n):
    r = robots[i][0]
    l = robots[i][1]
    if n_r > l:
        ans -= 1
    else:
        n_r = r

print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import numpy
import collections

rl = sys.stdin.readline

n = int(rl())
se = []
for _ in range(n):
    x, r = map(int, rl().split())
    start, end = x-r, x+r
    se.append([start, end])
se.sort(key=lambda x: x[1])

cur = se[0][0]
cnt = 0
for i in se:
    if cur <= i[0] <= i[1]:
        cur = i[1]
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
xl = [list(map(int, input().split())) for _ in range(n)]
xl2 = sorted([[x + l, x - l] for x, l in xl])

ans = 0
mr = xl2[0][1]
for r, l in xl2:
    if l >= mr:
        ans += 1
        mr = r
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import collections

sys.setrecursionlimit(10 ** 7)

# 1 ✕ 1 (int)
N = int(input().rstrip())

# N ✕ M
A = list(tuple(map(int, input().rstrip().split())) for _ in range(N))

array = []
for s, t in A:
    array.append((s + t, s - t))

array.sort()
# print(array)

ans = 0
t = -1e9
for e, s in array:
    if t <= s:
        t = e
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
L = [list(map(int,input().split())) for _ in range(n)]
L.sort(key=lambda x:x[0]+x[1])
seen=-10**10
cnt=0
for i in range(n):
    if seen<=L[i][0]-L[i][1]:
        seen=L[i][0]+L[i][1]
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    x, l = [0]*n, [0]*n
    for i in range(n):
        x[i], l[i] = map(int, input().split())
    hoge = []
    for i in range(n):
        hoge.append([x[i]+l[i], x[i]-l[i]])
    hoge.sort()
    t = -1000000000000000000000
    ans = 0
    for i in range(n):
        if t <= hoge[i][1]:
            ans += 1
            t = hoge[i][0]
    print(ans)
    return 0
 
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    N=int(input())
    A=[]
    for i in range(N):
        X,L=map(int,input().split())

        A.append([X-L,X+L])

    A=sorted(A, key=lambda x: x[1])
    cur=-(10**10)
    cnt=0
    for i in range(N):
        if A[i][0]<cur: continue
        else:
            cur=A[i][1]
            cnt+=1
    print(cnt)



    
    

    
resolve()