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())
lr = [[0,0]]*N

for i in range(N):
    X,L = map(int,input().split())
    lr[i] = [X-L,X+L]
lr_s = sorted(lr)

ans = 1
now_r = lr_s[0][1]

for i in range(1,N):
    next_l = lr_s[i][0]
    next_r = lr_s[i][1]
    if now_r > next_l: #かぶってるときは右端が小さい方を残す
        now_r = min(now_r,next_r)
        #ロボットの数の増減はプラマイゼロ
    else:
        #かぶってないときはロボットが増える
        ans += 1
        now_r = next_r
        
print(ans)

Submission status: Accepted

Solution code:
#input
N = int(input())
S = []
T = []
for i in range(N):
    X_temp, L_temp = map(int, input().split())
    S.append(X_temp - L_temp)
    T.append(X_temp + L_temp)

#output
import numpy as np
S = np.array(S)
T = np.array(T)
idx = np.argsort(T)

S = S[idx]
T = T[idx]
answer = 0
length = -10**10
for i in range(N):
    if length <= S[i]:
        answer += 1
        length = T[i]

print(answer)

Submission status: Accepted

Solution code:
import math
import sys

m=10**9 + 7 
sys.setrecursionlimit(1000010)
INF=10 ** 10
N = int(input())
XL = [list(map(int,input().split())) for _ in range(N)]
XLs =sorted([ [xl[0]+xl[1],xl[0]-xl[1]] for xl in XL ])
# print(N,XL,XLs)

t = -INF 
n = 0

for xl in XLs:
    if t <= xl[1]:
        t = xl[0]
        n = n + 1
print(n)

Submission status: Accepted

Solution code:

n = int(input())
ans = n
x = []
for i in range(n):
    a ,b= map(int,input().split())
    x.append([a-b, a+b])
x.sort()

tmp= x[0]
for i in range(n-1):
    if tmp[1] <= x[i+1][0]:
        tmp = x[i+1]
    elif tmp[1] <= x[i+1][1]:
        ans -= 1
    else:
        tmp = x[i+1]
        ans -= 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
XL = [tuple(map(int,input().split())) for i in range(N)]
XL.sort(key=lambda x: x[0]+x[1])
right = -float('inf')
ans = 0
for x,l in XL:
    s,t = x-l, x+l-1
    if s > right:
        right = t
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
from operator import itemgetter

N = int(input())
A = []

for _ in range(N):
    a, b = map(int, input().split())
    A.append((a - b, a + b))
A.sort(key=itemgetter(1))

res = 1
cur = A[0]

for i, a in enumerate(A):
    if i == 0:
        continue
    if a[0] >= cur[1]:
        res += 1
        cur = a

print(res)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def erase_overlap_intervals(intervals):
        """
        :type intervals: List[Interval]
        :rtype: int
        """
        result, prev = 0, 0
        for i in range(1, len(intervals)):
            if intervals[i][0] < intervals[prev][1]:
                if intervals[i][1] < intervals[prev][1]:
                    prev = i
                result += 1
            else:
                prev = i
        return result


def main():
    N = I()
    XL = [None] * N

    for i in range(N):
        X, L_ = MI()
        XL[i] = (X, L_, i)

    arr = [None] * N
    for i in range(N):
        arr[i] = (XL[i][0] - XL[i][1], XL[i][0] + XL[i][1])

    arr = sorted(arr, key=lambda a: a[1])
    print(N - erase_overlap_intervals(arr))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math,sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
lili=lambda:list(map(int,sys.stdin.readlines()))
li = lambda:list(map(int,input().split()))
#for deque append(),pop(),appendleft(),popleft(),count()
I=lambda:int(input())
S=lambda:input().strip()
mod = 1000000007

n=I()
a=[]
b=[]
for i in range(n):
    x,l=li()
    a.append([x-l,x+l])
a.sort()
l,r=a[0][0],a[0][1]
#print(a)
c=0
d=0
for i in range(1,n):
    k=a[i]
    p,q=k[0],k[1]
    if(l<=p and r>=q):
        l,r=p,q
        c+=1
    elif(r<p):
        l,r=p,q
    elif(r==p):
        l,r=p,q
    else:
        c+=1


print(n-c)

Submission status: Accepted

Solution code:
n = int(input())
robots = []
for i in range(n):
    x_tmp, l_tmp = (int(i) for i in input().split())
    robots.append([x_tmp - l_tmp, x_tmp + l_tmp])

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

Submission status: Accepted

Solution code:
n=int(input())

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

cnt=0
min=-10**18

for r,l in list:
 if min<=r:
  cnt+=1
  min=l
print(cnt)

Submission status: Accepted

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

arm_range = sorted(arm_range)

limit = arm_range[0][0]
ans = 1

for i in range(1,N):
    if arm_range[i][1] >= limit:
        ans += 1
        limit = arm_range[i][0] 

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
ll=[]
for _ in range(n):
    x,l=map(int,input().split())
    ll.append((x+l,x-l))
ll=sorted(ll)
ans=0
c=-10**10
for t,s in ll:
    if c<=s:
        c=t
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
li=[None]*n
for i in range(0,n):
    flag=True
    x,l=map(int, input().split())
    li[i]=(x+l, x-l)
li=sorted(li)
count=1
x,y=li[0]
for i in range(1,n):
    x2,y2=li[i]
    if y2 < x:
        continue
    count=count+1
    x=x2
print(count)

Submission status: Accepted

Solution code:
# -- coding utf-8 --
import itertools
from operator import itemgetter
N=int(input())
X=[]
L=[]
MIN=[]
MAX=[]
for i in range(N):
    x,l=map(int,input().split())
    X.append(x)
    L.append(l)
    MIN.append(x-l)
    MAX.append(x+l)
    #print(x,l)

MIN_MAX_LIST = list(zip(MIN, MAX))
#print(MIN_MAX_LIST)
#MIN_MAX_LIST.sort()
#print(MIN_MAX_LIST)

MIN_MAX_LIST_SORTED  = sorted(MIN_MAX_LIST, key=itemgetter(1))
#print(MIN_MAX_LIST_SORTED)
# [(1, 3), (3, 5), (5, 7), (7, 9), (9, 11)]
count=0
previous_MAX = -1000000000
for j in range(N):
    #print(MIN_MAX_LIST_SORTED[j][1])
    if previous_MAX <= MIN_MAX_LIST_SORTED[j][0]:
        count += 1
        previous_MAX = MIN_MAX_LIST_SORTED[j][1]
print(count)

Submission status: Accepted

Solution code:
N = int(input())

mylist = []
for n in range(N):
    x, l = map(int, input().split())
    mylist += [[x+l, x-l]]
#print(mylist)
mylist.sort()
#print(mylist)

mymin = -9999999999
myans = 0
for n in range(N):
    #print(mymin, mylist[n][1], mylist[n][0])
    if mymin <= mylist[n][1]:
        myans += 1
        mymin = mylist[n][0]
        
print(myans)

Submission status: Accepted

Solution code:
n = int(input())
robots = []
for i in range(n):
    x, l = [int(item) for item in input().split()]
    robots.append((x+l, x-l))
 
robots.sort()
#print(robots)

cnt = 0
node = -float("inf")
for end, start in robots:
    if start >= node:
        node = end
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())

lst = []
for i in range(n):
    xi, li = map(int, input().split())
    lst.append([xi, li])

lst_2 = []
for i in range(n):
    xi, li = lst[i][0], lst[i][1]
    lst_2.append([xi-li, xi+li])

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

cnt = 1
right = lst_2[0][1]
for i in range(1, n):
    if lst_2[i][0] >= right:
        right = lst_2[i][1]
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:

N = int(input())

RL = []

for i in range(N):

    x,l = map(int,input().split())
    RL.append([x+l,x-l])

RL.sort()

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

for i in range(N):

    if nrmax <= RL[i][1]:
        ans += 1
        nrmax = RL[i][0]

print (ans)

Submission status: Accepted

Solution code:
n = int(input())
robots = []
for _ in range(n):
    xi, li = map(int, input().split())
    robots.append((xi - li, xi + li))
robots.sort(key=lambda x: x[1])
ans = 0
pre_r = -float('inf')
for l, r in robots:
    if pre_r <= l:
        ans += 1
        pre_r = r
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [[0,0] for _ in range(n)]

for i in range(n):
    a[i][0],a[i][1]=map(int,input().split())
    a[i][0],a[i][1]=(a[i][0]-a[i][1]),(a[i][0]+a[i][1])
a.sort(key=lambda x: x[1])
INF = 10**10
preR = -INF
cnt=0
for L,R in  a:
    if L<preR:
        continue
    cnt+=1
    preR=R
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter

n = int(input())
robots = []
for line in sys.stdin:
    X, L = map(int, line.split())
    l, r = X - L, X + L
    robots.append((l, r))
robots.sort(key=itemgetter(1))

curr = -(10 ** 10)
ans = 0
for l, r in robots:
    if curr > l:
        continue
    ans += 1
    curr = r
print(ans)

Submission status: Accepted

Solution code:
import sys
from pprint import pprint

def solve(n, x, l):
    r = []
    for i in range(n):
        r.append((x[i] + l[i], x[i] - l[i]))

    pre_e = -1 * 10**9
    ans = 0
    for e, s in sorted(r):
        # print(e,s)
        # print("pre", pre)
        if  pre_e <= s:
            # print("remain")
            pre_e = e
            ans += 1
    print(ans)


if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    x = [0] * n
    l = [0] * n
    for i in range(n):
        x[i], l[i] = map(int, sys.stdin.readline().strip().split(" "))
    solve(n, x, l)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    robots = []
    for _ in range(n):
        x, l = map(int, input().split())
        robots.append((x-l, x+l))
    robots.sort(key=lambda x: x[1])
    count = 1
    robot = robots[0]
    for r in robots:
        if robot[1] <= r[0]:
            robot = r
            count += 1
    print(count)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from operator import itemgetter


def solve():
    N = int(input())
    XL = [[] for _ in range(N)]
    for i in range(N):
        XL[i] = list(map(int, input().split()))
    
    XL.sort(key=itemgetter(0))
    ans = N
    r = sum(XL[0])
    for i in range(1, N):
        if XL[i][0] - XL[i][1] < r:
            ans -= 1
            r = min(r, sum(XL[i]))
        else:
            r = sum(XL[i])
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter

input = sys.stdin.readline


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

    xlr.sort()

    ans = N
    mi = xlr[0][1]
    for i in range(N - 1):
        if xlr[i + 1][0] < mi:
            mi = min(xlr[i + 1][1], mi)
            ans -= 1
        else:
            mi = xlr[i + 1][1]


    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

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

cur = -1000000000
ans = 0
for i in range(n):
   if (cur <= r[i][1]):
      ans += 1
      cur = r[i][0]

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
ES = []
for i in range(N):
    x,l = list(map(int,input().split()))
    ES.append((x+l,x-l+1))
 
ES = sorted(ES)
# print(ES)

sel = []
cur = None
ans = 0
for E,S in ES:
    if cur is None or cur < S:
        sel.append((S,E))
        cur = E
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N, *XL = map(int, open(0).read().split())

A = sorted(((x - l, x + l) for x, l in zip(*[iter(XL)] * 2)), key=lambda x: x[1])

ans = 0
cur = -10 ** 9
for s, t in A:
    if cur <= s:
        ans += 1
        cur = t

print(ans)

Submission status: Accepted

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

t = [(x + l, x - l) for x, l in XL]
t.sort()
max_r = -float('inf')
result = 0
for i in range(N):
    r, l = t[i]
    if max_r <= l:
        result += 1
        max_r = r
print(result)

Submission status: Accepted

Solution code:
l=[]
for i in range(int(input())):
    x,y=map(int,input().split())
    l.append((x+y,x-y))
l.sort()
t,a=l[0][1],0
for j,i in l:
    if t<=i:
        a+=1
        t=j
print(a)

Submission status: Accepted

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

ans = n
r = ll.pop()[0]

while ll:
  while ll and ll[-1][1] > r:
    ans -= 1
    ll.pop()
  if ll:
    r = ll.pop()[0]

print(ans)

Submission status: Accepted

Solution code:
n = int(input().strip())
xl = [list(map(int, input().split())) for i in range(n)]
lst=[[0]*2 for _ in range(n)]

for i in range(n):
    lst[i][0]=xl[i][0]-xl[i][1]
    lst[i][1]=xl[i][0]+xl[i][1]

lst.sort(key=lambda x: x[1])
ans=0
last=-10**10
for i in range(n):
    if last <= lst[i][0]:
        ans+=1
        last=lst[i][1]
print(ans)

Submission status: Accepted

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


def main():
    N = int(input())
    robo = []
    for i in range(N):
        x, l = [int(x) for x in input().split()]
        robo.append((x-l, x+l))
    robo.sort()
    robo.sort(key=lambda x: x[1])

    ans = N
    l, r = robo[0]
    for i in range(1, N):
        if robo[i][0] < r:
            ans -= 1
        else:
            l, r = robo[i]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/keyence2020/tasks/keyence2020_b

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

areas = [(x - l, x + l) for x, l in zip(X, L)]
areas = sorted(areas, key=lambda x:x[-1])

# print(areas)

ok = [areas[0]]
for area in areas[1:]:
    if ok[-1][-1] <= area[0]:
        ok.append(area)

# print(ok)
print(len(ok))

Submission status: Accepted

Solution code:
n = int(input())
robots = []
for _ in range(n):
    xi, li = map(int, input().split())
    robots.append((xi + li, xi - li))
robots.sort()
ans = n
pre_right = robots[0][0]
for i in range(1, n):
    now_left = robots[i][1]
    if pre_right > now_left:
        ans -= 1
    else:
        pre_right = robots[i][0]
print(ans)

Submission status: Accepted

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

C.sort(key = lambda x: x[1])
ans = 0
a = -float("inf")
for i in range(N):
	if C[i][0] >= a:
		a = C[i][1]
	else:
		ans += 1

print(N-ans)

Submission status: Accepted

Solution code:
N=int(input())
ES = []
for i in range(N):
    x,l = list(map(int,input().split()))
    ES.append((x+l,x-l))
 
ES = sorted(ES)

sel = []
cur = None
ans = 0
for E,S in ES:
    if cur is None or cur <= S:
        sel.append((S,E))
        cur = E
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, X: "List[int]", L: "List[int]"):
    s = [X[i]-L[i] for i in range(N)]
    e = [X[i]+L[i] for i in range(N)]
    se = [[s[i],e[i]] for i in range(N)]
    se = sorted(se, key=lambda x:x[1])

    ans = [se[0]]

    for i in range(1, N):
        if se[i][0] < ans[-1][1]:
            continue
        else:
            ans.append(se[i])

    # print(ans)
    print(len(ans))

    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))  # type: int
    X = [int()] * (N)  # type: "List[int]"
    L = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        X[i] = int(next(tokens))
        L[i] = int(next(tokens))
    solve(N, X, L)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from operator import itemgetter

N = int(input())
X=[]
ans=0
for i in range(N):
    H = list(map(int, input().split()))
    O=[]
    O.append(H[0]-H[1])
    O.append(H[0]+H[1])
    X.append(O)
#print(X)
X=sorted(X, key=itemgetter(1))
S=X[0][1]
ans+=1
for i in range(len(X)):
    if(X[i][0]>=S):
        ans+=1
        S=X[i][1]
"""
while(len(X)>0):
    #print(X)
    ans+=1
    S=X[0][1]
    X.remove(X[0])
    I = []
    for i in range(len(X)):
        if(X[i][0]>=S):
            I.append(X[i])
    X=I
    #print(I)
"""


print(ans)

Submission status: Accepted

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

s.sort(key=lambda x: x[1])
ans, c = 0, -float("inf")

for l, r in s:
    if c > l: continue
    ans += 1
    c = r

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.sort(key=lambda _x: _x[1])
cnt = 1
limit = r[0][1]
for ri in r[1:]:
    if ri[0] >= limit:
        cnt += 1
        limit = ri[1]
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
xl = [list(map(int, input().split())) for _ in range(N)]
rl = []
for i in range(N):
    rl.append((xl[i][0] - xl[i][1], xl[i][0] + xl[i][1]))
rl.sort(key=lambda x: x[1])
cnt = 0
tmp = -10 ** 18

for i, j in rl:
    if tmp <= i:
        cnt += 1
        tmp = j
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
XL = [list(map(int,input().split())) for _ in range(N)]
r_l = []
for n in range(N):
  xl = XL[n]
  x = xl[0]
  l = xl[1]
  r_l.append([x-l,x+l])

r_l = sorted(r_l,key = lambda x:x[1])
ans = 1
l = r_l[0][1]
for a in r_l:
  if a[0]<l:
    continue
  else:
    ans += 1
    l = a[1]
    
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
li=[None]*n
for i in range(0,n):
    flag=True
    x,l=map(int, input().split())
    li[i]=(x+l, x-l)
li=sorted(li)
count=1
x,y=li[0]
for i in range(1,n):
    x2,y2=li[i]
    if y2 < x:
        continue
    count=count+1
    x=x2
print(count)

Submission status: Accepted

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

min_max = sorted([[list[0] - list[1], sum(list)] for list in robots], key=lambda val: val[1])
           
remove = 0
max_range = -1e9 - 1
for robot in min_max:
  if max_range <= robot[0]:
    max_range = robot[1]
  else:
    remove += 1
  
print(n - remove)

Submission status: Accepted

Solution code:
N = int(input())
X = [0] * N
for i in range(N):
    x, l = map(int, input().split())
    X[i] = x, l, x - l, x + l

X.sort(key=lambda x: x[3])  # 端点順
right = X[0][3]
count = 1
for i in range(1, N):
    if right <= X[i][2]:
        count += 1
        right = X[i][3]

print(count)

Submission status: Accepted

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

if n == 1:
  print(n)
else:
  XL = sorted(X, key=lambda x: x[3])

  # print(XL)

  ans = 0
  temp = -1 * (10**9)

  for i in range(n):
    if temp <= XL[i][2]:
      ans += 1
      temp = XL[i][3]

  print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

xl = sorted(xl)

cur = -10**9
ans = 0
for r in xl:
    if cur <= r[1]:
        ans +=1
        cur = r[0]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
arms = []
for _ in range(N):
    x1, l1 = map(int, input().split())
    arms.append([x1+l1, x1-l1])
    
arms.sort()

last = -(10 ** 9)
ans = 0
for i in range(N):
    if last <= arms[i][1]:
        ans += 1
        last = arms[i][0]
    else:
        continue
    
print(ans)

Submission status: Accepted

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

cur = -float('inf')
ans = 0
for i in range(n):
    t, s = robots[i]
    if cur <= s:
        ans += 1
        cur = t

print(ans)

Submission status: Accepted

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

grid = [list([0,0]) for i in range(n)]

for i in range(n):
    grid[i][0] = x[i][0] - x[i][1]
    grid[i][1] = x[i][0] + x[i][1]

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

cnt = 1
a = new_grid[0][1]

for i in range(n):
    if a <= new_grid[i][0]:
        cnt += 1
        a = new_grid[i][1]
print(cnt)

Submission status: Accepted

Solution code:
from bisect import bisect_left as lower_bound
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


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 StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True

def main():
    N = I()
    XL = [None] * N
    ans = 0

    for i in range(N):
        X, L_ = MI()
        XL[i] = (X, L_, i)

    arr = [None] * N
    for i in range(N):
        arr[i] = (XL[i][0] - XL[i][1], XL[i][0] + XL[i][1])

    arr = sorted(arr, key=lambda a: a[1])
    maxv = -(10 ** 9)
    cur = maxv
    for i in range(N):
        if cur <= arr[i][0]:
            cur = arr[i][1]
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

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.sort()

ans = 0
last = -1e10
for r, l in R:
    if last <= l:
        ans += 1
        last = r
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
S = [tuple(map(int, input().split())) for i in range(N)]
T = list(map(lambda j:(j[0]-j[1], j[0]+j[1]), S))

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

for i, t in enumerate(T):
  if i>0:
    if end <= t[0]:
      res += 1
      start = t[0]
      end = t[1]
  else:
    start = t[0]
    end = t[1]
    res = 1

print(res)

Submission status: Accepted

Solution code:
n = int(input())
ans = 1
a = []
d = {}
for i in range(n):
  x,l = map(int, input().split())
  a.append((x+l,x-l))
if n == 1:
  print(ans)
else:
  a.sort(key=lambda x:(x[0],x[1]))
  gl = a[0][0]
  st = a[0][1]
  for i in range(1,n):
    if gl<=a[i][1]:
      ans += 1
      gl = a[i][0]
  print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
from operator import itemgetter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
LR = []
for i in range(N):
    x, l = MAP()
    LR.append((x-l, x+l))

LR.sort(key=itemgetter(1))
cur = -INF
cnt = 0
for l, r in LR:
    if cur <= l:
        cur = r
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
xl = []
for i in range(n):
    xx,ll = inm()
    xl.append((xx+ll,xx-ll))
xl.sort()

ddprint(xl)

cnt = 1
i = 0
while i<n-1:
    nxtj = -1
    for j in range(i+1,n):
        if xl[i][0]<=xl[j][1]:
            #ddprint("j {} found".format(j))
            cnt += 1
            nxtj = j
            break
    i = nxtj if nxtj>0 else n
    #ddprint("i {} j {} nxtj {}".format(i,j,nxtj))

print(cnt)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    nodes = []

    for _ in range(N):
        X, L = map(int, input().split())
        end = X + L
        start = X - L
        nodes.append((end, start))

    nodes.sort()

    last_end = -999999999999999999
    ans = 0
    for node in nodes:
        end, start = node
        if last_end <= start:
            ans += 1
            last_end = end

    print(ans)


main()

Submission status: Accepted

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

d.sort()
p = d[0][1]
ans = n
for i in range(1,n):
    if d[i][0] < p:
        ans -= 1
        p = min(p,d[i][1])
    else:
        p = d[i][1]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
x = []
for i in range(n):
    X,L = map(int, input().split())
    x.append([X-L,X+L])
x.sort(key=lambda x:x[0])
ans = n
tmp = x[0][1]
for i in range(1,n):
    if tmp>x[i][0]:
        ans -=1
        tmp = min(tmp,x[i][1])
    else:
        tmp = x[i][1]
print(ans)

Submission status: Accepted

Solution code:
import math
N = int(input())
X = []
for _ in range(N):
  x, l = map(int,input().split())
  X.append([x+l, x-l])
sorted_X = sorted(X, key=lambda x:(x[0], x[1]))
ans = 1
cnt = sorted_X[0][0]
for i in range(N):
  if sorted_X[i][1] >= cnt:
    ans += 1
    cnt = sorted_X[i][0]
print(ans)

Submission status: Accepted

Solution code:
# 参考
# https://atcoder.jp/contests/keyence2020/submissions/9575705
#------------------------------------------

n = int(input())
robots = []

for i in range(n):
    x, l = map(int, input().split())
    robots.append([x + l, x - l])
    
#robotsという配列には
#・[0]に右側の手で届く範囲
#・[1]に左側の手で届く範囲
#が格納されている。
    
robots.sort()

r = - 10 ** 9 - 1
cnt = 0
for i in range(n):
    if r <= robots[i][1]:#この式で、左側に腕を伸ばした時にぶつからないことを指している
        cnt += 1
        r = robots[i][0]#最小値には右側に腕を伸ばした場合を代入
print(cnt)

Submission status: Accepted

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

ans = [[0 for i in range(2)] for j in range(n)]
for i in range(n):
    ans[i][1]=(x[i]+l[i])
    ans[i][0]=max(0,x[i]-l[i])
ans.sort()
count=1
j=0
for i in range(n-1):
    
    if ans[j][1]<=ans[i+1][0] :
        count+=1
        j=i+1
    else:
        if ans[j][1]>ans[i+1][1]:
           j=i+1  
print(count)

Submission status: Accepted

Solution code:
n=int(input())
X=[]
for i in range(n):
    x,l=[int(_) for _ in input().split()]
    X+=[(x-l,x+l)]
X.sort(key=lambda x:x[0])
ans=n
tmp=X[0][1]
for i in range(1,n):
    if tmp>X[i][0]:
        ans-=1
        tmp=min(tmp,X[i][1])
    else:
        tmp=X[i][1]
print(ans)

Submission status: Accepted

Solution code:
from operator import itemgetter

n = int(input())
data = [()]*n
for i in range(n):
    x, l = map(int, input().split())
    data[i] = (x-l,x+l)
data.sort(key = itemgetter(1))
ans = 0
prev_r = -10**18
for l, r in data:
    if prev_r >  l:
      continue
    ans += 1
    prev_r = r

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
ans=0
cnt=-(10**9)-1
li=[]
for i in range(n):
    X,L=map(int,input().split())
    li.append([X+L,L])
li=sorted(li,key=lambda x:x[0])
for i in range(n):
    if cnt>li[i][0]-li[i][1]*2:
        ans+=1
    else:
        cnt=li[i][0]
print(n-ans)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


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

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

    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
itv=[]
for _ in range(n):
    x,l=map(int,input().split())
    itv.append((x+l,x-l))
itv.sort()
ass = 0
tt = -float("inf")
for i in range(n):
    if tt <= itv[i][1]:
        ass += 1
        tt = itv[i][0]
print(ass)