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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  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]))

#p(X)
#p(L)
#p(A)
#p(B)


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)

Submission status: Accepted

Solution code:
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])
#print(xls)

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

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
N = int(input()) #number of robots

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

robo_list.sort()
#print(robo_list)

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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:

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)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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()
# print(arr)
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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()
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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


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

    for i in range(n):
        xi, li = map(int, input().split())
        # y.append((xi - li + 1, xi + li - 1))
        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()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
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)

Submission status: Accepted

Solution code:
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:
    

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)

Submission status: Accepted

Solution code:
#わからんけどとりあえず貪欲
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
n = int(input())
xl_lis = [list(map(int,input().split())) for i in range(n)]
tempx = -(10**10)
ans = 0
xl_lis.sort()
# print(xl_lis)
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])
# print(L) #kesu

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

print(count)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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(l[i],buf,count)
print(count)

Submission status: Accepted

Solution code:
import bisect
import collections
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

n = ri()
ls = rils(n)
ls = [(x - l + 0.5, x + l - 0.5) for x, l in ls]
ls.sort(key=lambda x: x[1])
pos = [r for _, r in ls]

dp = collections.defaultdict(int)
prev_r = None
for l, r in ls:
    i = bisect.bisect_left(pos, l)
    if i > 0:
        dp[r] = max(dp[r], dp[pos[i - 1]] + 1)
    else:
        dp[r] = max(dp[r], 1)
    if prev_r:
        dp[r] = max(dp[r], dp[prev_r])
    prev_r = r
print(max(dp.values()))

Submission status: Accepted

Solution code:
N = int(input())
xl = []
for i in range(N):
    x,l = list(map(int,input().split()))
    xl.append([x - l, x + l])
    
#xl = [[1,2],[3,4],[5,6]]
xl.sort(key=lambda x:x[1])
ans = 1
tmp = xl[0][1]
for i in range(1,N):
    if xl[i][0] >= tmp:
        ans += 1
        tmp = xl[i][1]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = []
for _ in range(N):
    x, l = map(int, input().split())
    A.append((x+l, x-l+1))
A.sort()
now = A[0][0]
ans = 1
for r, l in A:
    if now<l:
        ans+=1
        now = r
print(ans)

Submission status: Accepted

Solution code:
def Segment(x, l, n): 
    if (n == 1): 
        return 1
    ans = 1
      
    for i in range(1, n): 
        if (x[i] - l[i] >= x[i - 1]): 
            ans += 1
        else:
            x[i] = x[i-1] 
        # print(x, l)
        # if (x[i] + l[i] < x[i + 1]): 
        #     x[i] = x[i] + l[i] 
        #     ans += 0
    return ans 

def main():
    N = int(input())
    X, L = [], []
    for n in range(N):
        x, l = list(map(int, input().split()))
        X.append(x+l)
        L.append(2*l)
    X, L = zip(*sorted(zip(X, L)))
    X = list(X)
    L = list(L)

    print(Segment(X, L, N))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = sorted((tuple(map(int, input().split())) for _ in range(n)), key=sum)
r = 0
p = -10**9
for x, l in a:
  if x - l >= p:
    r += 1
    p = x + l
print(r)

Submission status: Accepted

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

first_robot=ls.pop(0)
prev_right=first_robot[0]+first_robot[1]

for i,robot in enumerate(ls):
    left=robot[0]-robot[1]
    right=robot[0]+robot[1]
    if left<prev_right:
        n-=1
        if right<prev_right:
            prev_right=right
    else:
        prev_right=right
print(n)

Submission status: Accepted

Solution code:
N = int(input())
XL = []
for i in range(N):
    XL.append(list(map(int,input().split())))
XL.sort(key=lambda x:x[0])
ans = 0
left = XL[0][0]-XL[0][1]
right = XL[0][0]+XL[0][1]
for i in range(1,N):
    new_left = XL[i][0]-XL[i][1]
    new_right = XL[i][0]+XL[i][1]
    #if no overlap
    if new_left >= right:
        left = new_left
        right = new_right
    else:
        ans += 1
        if new_right < right:
            left = new_left
            right = new_right
print(N-ans)

Submission status: Accepted

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

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

for i in range(n):
    a = c[i][0] - c[i][1]
    b = c[i][0] + c[i][1]
    c[i][0] = a
    c[i][1] = b

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

Submission status: Accepted

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

paths = []
for x, l in XL:
    paths.append((x-l, x+l))
paths = sorted(paths, key=lambda x: x[1])

ans = 0
cur = None
for (l, r) in paths:
    if cur is None or cur <= l:
        ans += 1
        cur = r

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
ps = []
for i in [0]*N:
    X,L = map(int, input().split(' '))
    ps.append((X-L,X+L))

ps.sort(key=lambda x:x[1])
now = -10**10
ans = 0
for l,r in ps:
    if now <= l:
        now = r
        ans += 1
print(ans)

Submission status: Accepted

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

x=[[d[i][0]+d[i][1],d[i][0],d[i][1]] for i in range(n)]
x.sort()
t=0
t2=-10**9-1
ans=0
for i in range(n):
  if t<x[i][0] and t2 <= (x[i][1]-x[i][2]):
    ans+=1
    t=x[i][0]
    t2=x[i][0]
print(ans)

Submission status: Accepted

Solution code:
H = int(input())
list = []
for i in range(H): #因数注意！
    n = input()    
    m = n.split()
    p = [int(i) for i in m]
    q = [p[0]-p[1],p[0]+p[1]]
    list.append(q)
newlist = sorted(list)
z = [-1000000000000000000,-100000000000000000]
a = 0
for i in newlist:
    if i[0] >= z[1]:
        z = i
        a = a + 1
    else:
        if i[1] < z[1]:
            z = i

print(a)

Submission status: Accepted

Solution code:
#%%
n = int(input())
x = [0] * n
l = [0] * n
a = [[0, 0] for _ in range(n)]
for i in range(n):
    x[i], l[i] = map(int, input().split())
    a[i] = [x[i]-l[i], x[i]+l[i]]

a.sort(key=lambda x: x[1])
#print(a)

ans = 0
t = -(10**10)
for i in range(n):
    if a[i][0] >= t:
        ans += 1
        t = a[i][1]
print(ans)

Submission status: Accepted

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

segs = sorted([(p - r, p + r) for p, r in a], key=lambda x: x[1])
dp = [1] + [0] * (n - 1)
for i in range(1, n):
    dp[i] = dp[i - 1]
    left, right = -1, i
    while left + 1 < right:
        mid = (left + right) >> 1
        if segs[mid][1] <= segs[i][0]:
            left = mid
        else:
            right = mid
    if left != -1:
        dp[i] = max(dp[i], 1 + dp[left])
print(dp[n - 1])

Submission status: Accepted

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




ans=0
end=-10**(19)
for i in range(N):
    if XL[i][0]>=end:
        ans+=1
        end=XL[i][1]
        
print(ans)

Submission status: Accepted

Solution code:
''' Hey stalker :) '''
INF = 10**10
def main():
    #print = out.append
    ''' Cook your dish here! '''
    n = get_int()
    points = defaultdict(list)
    dp = [0]
    for _ in range(n):
        x, l = get_list()
        points[x+l].append(max(0, x-l))
        if max(0, x-l) not in points:
            points[max(0, x-l)] = []
    indexOfPoint = {0: 0}
    for i, point in enumerate(sorted(points)):
        indexOfPoint[point] = i+1
        dp.append(dp[-1])
        for cp in points[point]:
            dp[-1] = max(dp[-1], 1 + dp[indexOfPoint[cp]])
        continue
    print(dp[-1])


''' Pythonista fLite 1.1 '''
import sys
from collections import defaultdict, Counter
from bisect import bisect_left, bisect_right
#from functools import reduce
#import math
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
main()
#[main() for _ in range(int(input()))]
#print(*out, sep='\n')

Submission status: Accepted

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

remove = 0
reach = 0

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

    if i == 0:
        reach = right
        continue

    if reach > left:
        reach = min(reach, right)
        remove += 1
    else:
        reach = right

print(N - remove)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, X: "List[int]", L: "List[int]"):

    # 区間に変換する
    segs = [(x-l, x+l) for x, l in zip(X, L)]
    segs.sort(key=lambda x: x[1])  # 尻でソート

    # DP i個目の区間まで考えた時の残せる数
    DP = [0]*N
    DP[0] = 1
    for i in range(1, N):
        # 重なっていなければ
        if segs[i-1][1] <= segs[i][0]:
            DP[i] = DP[i-1]+1
        else:
            # 加えないか
            DP[i] = DP[i-1]
            # 重なるものを抜いた場合の個数+1
            left = -1
            right = i-1
            while right-left > 1:
                mid = (right+left)//2
                if segs[mid][1] <= segs[i][0]:
                    left = mid
                else:
                    right = mid
            # すべて重なるケースは区別
            if left == -1:
                buf = 1
            else:
                buf = DP[left]+1
            DP[i] = max(buf, DP[i-1])
    print(DP[-1])

    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:
n = int(input())

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

ass = 1
tt = itv[0][0]
for i in range(1, n):
    if tt <= itv[i][1]:
        ass += 1
        tt = itv[i][0]
print(ass)

Submission status: Accepted

Solution code:
import bisect

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

robots.sort()
right_x_list = [x[0] for x in robots]
# 最も右翼がiのときの最大の残せる個数
dp = [0 for _  in range(n + 1)]

for i in range(0, n):
	j = bisect.bisect_right(right_x_list, robots[i][1] - robots[i][2])
	#print(i, j)
	dp[i + 1] = max(dp[j] + 1, dp[i])

print(dp[-1])

Submission status: Accepted

Solution code:
n = int(input())

itv = []
for i in range(n):
    x,l = map(int,input().split())
    itv.append([x+l-0.1,x-l+0.1])
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)

Submission status: Accepted

Solution code:
# coding: utf-8
N=int(input())
XL=[]

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

for i in range(1,N):
    l=XL[i][0]-XL[i][1]
    if r > l:
        ans-=1
        if r > XL[i][0]+XL[i][1]:
            r=XL[i][0]+XL[i][1]
    else:
        r=XL[i][0]+XL[i][1]

print(ans)

Submission status: Accepted

Solution code:
import math
N = int(input())
arms = [list(map(int,input().split(" "))) for _ in range(N)]
robots = [((x-l),(x + l)) for x,l in arms]
robots = sorted(robots,key=lambda x:(x[0],x[1]))
ans = N
l,r = robots[0] # r→ limit 現状のlimit
for robot in robots[1:]:
    newl,newr = robot
    if r > newl: # 被っていたら除去
        if  r > newr: #前にあったやつを除去する場合
            r = newr

        ans -= 1
    else:
        l = newl
        r = newr

print(ans)

Submission status: Accepted

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

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

# print(L)

ans = 1
right = L[0][1]
for i in range(1, n):
    next_left = L[i][0]
    next_right = L[i][1]

    if next_left < right:
        continue
    else:
        ans += 1
        right = next_right

print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    R = []
    for _ in range(N):
        x, l = map(int, input().split())
        R.append((x - l, x + l))
    R.sort(key=lambda x: x[1])
    r = 0
    m = -10**10
    for xl, xr in R:
        if m <= xl:
            m = xr
            r += 1
    print(r)

main()