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: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 12 07:49:36 2020

@author: naoki
"""
N = int(input())
xl = [list(map(int, input().split())) for _ in range(N)]

left_right = [[row[0]-row[1], row[0]+row[1]] for row in xl]
left_right = sorted(left_right, key = lambda x:int(x[1]))
count = 0
now = -10000
for row in (left_right):
    if row[0] < now:
        continue
    else:
        count += 1
        now = row[1]
print(count)

Submission status: Wrong Answer

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

lis.sort()
flg = [False] * n
cnt = len(lis)

for i in range(1, n):
    if lis[i][0] < lis[i-1][1] and not flg[i-1]:
        cnt -= 1
        flg[i] = True
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
xl=[list(map(int,input().split())) for i in range(n)]
xl=[i+[i[0]-i[1],i[0]+i[1]] for i in xl] # [point,arm,left,right]
xl.sort(key=lambda x: x[2])
i=0
ans=n
while i<len(xl)-1:
  if xl[i][-1]>xl[i+1][2]:
    del xl[i+1]
    ans-=1
  else:
    i+=1
print(ans)

Submission status: Wrong Answer

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

Q.sort()
ans = 1
tmp = Q[0][0] + Q[0][1]
for x, l in Q[1:]:
    if tmp < x-l or tmp == x-l:
        ans += 1
        tmp = x+l
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
xl = [list(map(int, readline().split())) for i in range(n)]
pm = [[0] * 2 for _ in range(n)]
for i in range(n):
    pm[i][0] = xl[i][0] + xl[i][1]
    pm[i][1] = xl[i][0] - xl[i][1]
pm.sort(key=lambda x: x[1])
ans = 1
check = pm[0][0]
for i in range(1, n):
    if check <= pm[i][1]:
        check = pm[i][0]
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
xl = [list(map(int, readline().split())) for i in range(n)]
pm = [[0] * 2 for _ in range(n)]
for i in range(n):
    pm[i][0] = xl[i][0] + xl[i][1]
    pm[i][1] = xl[i][0] - xl[i][1]
pm.sort(key=lambda x: x[1])
ans = 1
check = pm[0][0]
for i in range(1, n):
    if check <= pm[i][1]:
        check = pm[i][1]
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
robot = [input().split() for i in range(N)]

le = [[int(i[0])-int(i[1]), int(i[0])+int(i[1])] for i in robot]
le.sort(key = lambda x:x[1])

ans = 0
floor = -10**5
for i in range(N):
    if floor <= le[i][0]:
        ans += 1
        floor = le[i][1]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
xl = [list(map(int, input().split())) for _ in range(n)]
le = [[p[0]-p[1], p[0]+p[1]] for p in xl]
le.sort(key= lambda x: x[1])

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
is_left = [True for i in range(n)]

l = [list(map(int,input().split())) for i in range(n)]
l = [[x+length,length] for x, length in l]
l.sort(key=lambda x:x[0])

for i in range(1,n):
    if l[i][0] - (2*l[i][1]) < l[i-1][0]:
        if is_left[i-1] == True:
            is_left[i] = False

print(sum(is_left))

Submission status: Wrong Answer

Solution code:
n = int(input())

start = []
is_left = [True for i in range(n)]
length = []

for _ in range(n):
    x, l = map(int,input().split())
    start.append(x+l)
    length.append(l)

sorted_length = []
start_i = [i for i in range(n)]
start_i.sort(key=lambda x:start[x])
start.sort()
for i in start_i:
    sorted_length.append(length[i])


for i in range(1,n):
    if start[i] - (2*sorted_length[i]) < start[i-1]:
        if is_left[i-1] == True:
            is_left[i] = False

print(sum(is_left))

Submission status: Wrong Answer

Solution code:
n = int(input())

start = []
is_left = [True for i in range(n)]
length = []

for _ in range(n):
    x, l = map(int,input().split())
    start.append(x+l)
    length.append(l)
    
start.sort()

for i in range(1,n):
    if start[i] - (2*length[i]) < start[i-1]:
        if is_left[i-1] == True:
            is_left[i] = False

print(sum(is_left))

Submission status: Wrong Answer

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

X = sorted(X, key=lambda x:x[1])
a = -2**10
ans = 0
for i in range(N):
    if X[i][0] >= a:
        a =X[i][1]
        ans +=1
    else:
        continue
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

arms_range_list = sorted(arms_range_list)


count = 0
max_arm_position_now = -int(1e10)
for i in range(N):
    min_arm_position_next = int(arms_range_list[i][0])
    if min_arm_position_next >= max_arm_position_now:
        max_arm_position_now = int(arms_range_list[i][1])
        count += 1


print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

arms_range_list = sorted(arms_range_list)


count = 0
max_arm_position_now = -int(1e10)
for i in range(N):
    min_arm_position_next = arms_range_list[i][0]
    if min_arm_position_next >= max_arm_position_now:
        max_arm_position_now = arms_range_list[i][1]
        count += 1


print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

arms_range_list = sorted(arms_range_list)


count = 0
max_arm_position_now = -float('inf')
for i in range(N):
    min_arm_position_next = arms_range_list[i][0]
    if min_arm_position_next >= max_arm_position_now:
        max_arm_position_now = arms_range_list[i][1]
        count += 1


print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
hani=[]
for i in range(n):
    x,l=map(int,input().split())
    hani.append([x,l])
hani2=sorted(hani)
#print(hani2)
no=0 #削除するロボット
bef=0
af=1
for i in range(n-1):
    a,b,a2,b2=hani2[bef][0],hani2[bef][1],hani2[af][0],hani2[af][1]
    if a<=a2<b:
        no+=1
        if b<b2: #前者を採用
            af+=1
        else:
            bef=af
            af+=1
    else:
        bef=af
        af+=1
print(n-no)

Submission status: Wrong Answer

Solution code:
n=int(input())
hani=[]
for i in range(n):
    x,l=map(int,input().split())
    hani.append([x-l,x+l])
hani2=sorted(hani)
#print(hani2)
no=0 #削除するロボット
bef=0
af=1
for i in range(n-1):
    a,b,a2,b2=hani2[bef][0],hani2[bef][1],hani2[af][0],hani2[af][1]
    if a<=a2<b:
        no+=1
        if b<b2: #前者を採用
            af+=1
        else:
            bef+=1
            af+=1
    else:
        bef+=1
        af+=1
print(n-no)

Submission status: Wrong Answer

Solution code:
n=int(input())
hani=[]
for i in range(n):
    x,l=map(int,input().split())
    hani.append([x-l,x+l])
hani2=sorted(hani)
no=0 #削除するロボット
bef=0
af=1
for i in range(n-1):
    a,b,a2,b2=hani[bef][0],hani[bef][1],hani[af][0],hani[af][1]
    if a<=a2<b:
        no+=1
        if b<b2: #前者を採用
            af+=1
        else:
            bef+=1
            af+=1
    else:
        bef+=1
        af+=1
print(n-no)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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

count = 0
i = arm[0][0]
for start, end in arm:
    if start < i:
        continue
    i = end
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

arm = {}
for i in range(N):
    X, L = map(int, input().split())
    arm[X - L] = X + L

arm = sorted(arm.items(), key=lambda x: x[1])
print(arm)

count = 0
i = -float("inf")
for item in arm:
    if item[0] < i:
        continue
    i = item[1]
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

arm = {}
for i in range(N):
    X, L = map(int, input().split())
    arm[X - L] = X + L

arm = sorted(arm.items(), key=lambda x: x[1])

count = 0
i = arm[0][0]
for item in arm:
    if item[0] >= i:
        i = item[1]
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

arm = {}
for i in range(N):
    X, L = map(int, input().split())
    arm[X - L] = X + L

arm = sorted(arm.items(), key=lambda x: x[1])

count = 0
i = arm[0][0]
for item in arm:
    if item[0] < i:
        continue
    else:
        i = item[1]
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

arm = {}
for i in range(N):
    X, L = map(int, input().split())
    arm[X - L] = X + L

arm = sorted(arm.items(), key=lambda x: x[1])

count = 1
i = arm[0][1]
for item in arm:
    if item[0] < i:
        continue
    else:
        i = item[1]
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
xl = [list(map(int,input().split())) for i in range(n)]
xl.sort()
i=0
ans=n
while i<len(xl)-1:
  r=xl[i][0]+xl[i][1]
  while r>xl[i+1][0]-xl[i+1][1]:
    del xl[i+1]
    ans-=1
    if i==len(xl)-1:
      break
  i+=1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
d = [[0, 0] for _ in range(n)]
for i in range(n):
    d[i] = list(map(int, input().split()))
d = [[dd[0], dd[0]+dd[1]] for dd in d]
d.sort(key=lambda x: x[1])
ans = 0
target = 0
for dd in d:
    if target == 0:
        ans += 1
        target = dd[1]
    else:
        if dd[0] >= target:
            ans += 1
            target = dd[1]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

input = lambda: sys.stdin.readline().rstrip()

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

ans = n
tmp = X_L[0][1]
for lower, upper in X_L[1:]:
  if lower < tmp:
    ans -= 1
  else:
    tmp = upper

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

input = lambda: sys.stdin.readline().rstrip()

n = int(input())
X_L = []
X_L_append = X_L.append
for _ in range(n):
    x, l = map(int, input().split())
    X_L_append((x-l, x, x+l))
X_L.sort(reverse=True)

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

Submission status: Wrong Answer

Solution code:
import sys

input = lambda: sys.stdin.readline().rstrip()

n = int(input())
X_L = []
X_L_append = X_L.append
for _ in range(n):
    x, l = map(int, input().split())
    X_L_append((x-l, x, x+l))
X_L.sort(reverse=True)

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

Submission status: Wrong Answer

Solution code:
import sys

input = lambda: sys.stdin.readline().rstrip()

n = int(input())
X_L = []
X_L_append = X_L.append
for _ in range(n):
    x, l = map(int, input().split())
    X_L_append((x-l, x))
X_L.sort(reverse=True)

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

Submission status: Wrong Answer

Solution code:
N=int(input())
XL=[list(map(int,input().split())) for i in range(N)]
XL.sort()
a=-float("inf")
ans=0
x,l=XL[0]
for i in range(N):
    X,L=XL[i]
    if X-L>=a:
        ans+=1
        a=X+L
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
XL=[list(map(int,input().split())) for i in range(N)]
XL.sort()
ans=1
x,l=XL[0]
for i in range(1,N):
    X,L=XL[i]
    if x<=X-L:
        ans+=1
        x,l=X,L
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[[0]*2 for i in range(N)]
for i in range(N):
    A[i][0],A[i][1]=map(int,input().split())
A=sorted(A)
ans=[]
ans.append(A[0])
for i in range(1,len(A)):
    if (ans[-1][0]+ans[-1][1])<=(A[i][0]-A[i][1]):
        ans.append(A[i])
print(len(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
M = [list(map(int, input().split())) for i in range(N)]
Q = [[m[0]-m[1], m[0]+m[1]] for m in M]
Q = list(sorted(Q, key=lambda x: x[0]))
NUM = 0
END = -10**9
for q in Q:
  if q[0] >= END:
    NUM += 1
    END = q[1]
print(NUM)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)
from collections import defaultdict
from bisect import *
mod = 10**9+7

N = int(input())
XL = [list(map(int, input().split())) for i in range(N)]
XL.sort()
cnt, last = 0, XL[0]
for x, l in XL[1:]:
    if x-l < last[0]+last[1]:
        cnt += 1
    else:
        last = [x, l]
print(N-cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
XL = [[int(x) for x in input().split()] for _ in range(n)]
XL.sort(key=lambda xl: xl[0] - xl[1])
count = 0
while len(XL) > 0:
    count += 1
    limit = XL[0][0] + XL[0][1]
    while len(XL) > 0 and XL[0][0] - XL[0][1] < limit:
        XL.pop(0)
print(count)

Submission status: Wrong Answer

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

while i < n:
    s = X[i][0]
    while i < n and X[i][0] < s + X[i][1]:
        i += 1
    p = X[i-1][0]
    while i < n and X[i][0] < p + X[i][1]:
        i += 1

    ans += 1

print(ans)

Submission status: Wrong Answer

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 = 0
tmp = -float('inf')
for l, r in R:
    if tmp <= r:
        ans += 1
        tmp = l
print(ans)

Submission status: Wrong Answer

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 = 0
tmp_r = -1
for l, r in R:
    if tmp_r <= l:
        ans += 1
        tmp_r = r
print(ans)

Submission status: Wrong Answer

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

XL=sorted(XL)
count=0

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

print(N-count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = []
for i in range(N):
    xi, li = map(int, input().split())
    S.append([xi - li, xi + li])

S.sort()

ans = 0
last = -1*float('Inf')
for si in S:
    if si[0] >= last:
        ans += 1
        last = si[1]

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
R=[[1]*2 for _ in range(N)]
flag=0
for i in range(N):
    X,L=map(int,input().split())
    R[i][0]=X
    R[i][1]=L
R.sort()
for i in range(N-1):
    r=R[i][0]+R[i][1]
    l=R[i+1][0]-R[i+1][1]
    if r>l and flag==0:
        N-=1
        flag=1
    else:
        flag=0
print(N)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n = int(input())
x_l = [0]*n
x_plus_l = [0]*n
# 左端から貪欲に埋めることができる
# 証明：f(x)をx以降に最大で残せる数とすると、現時点の可動域の右端をXとして　Xi<Xj の時、f(xi) >= f(xj)がそれまでの選び方によらず成り立つから
# つまり、X< xi-liとなるiの中でxi+liがminを選べば良い
# xi+Liでソートして毎回2分探索するとO(nlogn)で終わる => xi-liはソートされてないので2分探索できない
# xi-liでソートして、X以上の要素に対して、順番に X = max(X,xi+li)として更新し、
# X > Xi-Li になったらcnt += 1 し、その時点でXは確定する、と言うように尺取的なことをすると、
# ロボットを通過するのは各ロボットに対し、一度しかないのでO(n)でいける
# 変数：X,cnt
for i in range(n):
    x,l = map(int,input().split())
    x_l[i] = x-l
    x_plus_l[i] = x+l
x_l,x_plus_l = zip(*sorted(zip(x_l,x_plus_l)))
cnt = 1# 初期点は左端
i = 1#0から順番に見て行く
X = min(x_plus_l)#初期化 はx+l のmin
#print(X,x_l,x_plus_l)
#最初だけ 右端がminになる点をとるので x_l[i] >= Xになるように初期の調整をする
while i < n:# nになったら全点を探索しているので終了
    if x_l[i] >= X:
        cnt += 1
        #print(i,cnt)
    else:
        if cnt != 1:
            X = min(X,x_plus_l[i])
    i += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n = int(input())
x_l = [0]*n
x_plus_l = [0]*n
# 左端から貪欲に埋めることができる
# 証明：f(x)をx以降に最大で残せる数とすると、現時点の可動域の右端をXとして　Xi<Xj の時、f(xi) >= f(xj)がそれまでの選び方によらず成り立つから
# つまり、X< xi-liとなるiの中でxi+liがminを選べば良い
# xi+Liでソートして毎回2分探索するとO(nlogn)で終わる => xi-liはソートされてないので2分探索できない
# xi-liでソートして、X以上の要素に対して、順番に X = max(X,xi+li)として更新し、
# X > Xi-Li になったらcnt += 1 し、その時点でXは確定する、と言うように尺取的なことをすると、
# ロボットを通過するのは各ロボットに対し、一度しかないのでO(n)でいける
# 変数：X,cnt
for i in range(n):
    x,l = map(int,input().split())
    x_l[i] = x-l
    x_plus_l[i] = x+l
x_l,x_plus_l = zip(*sorted(zip(x_l,x_plus_l)))
cnt = 1# 初期点は左端
i = 1#0から順番に見て行く
X = min(x_plus_l)#初期化 はx+l のmin
#print(X,x_l,x_plus_l)
#最初だけ 右端がminになる点をとるので x_l[i] >= Xになるように初期の調整をする
while i < n:# nになったら全点を探索しているので終了
    if x_l[i] >= X:
        cnt += 1
        #print(i,cnt)
    else:
        if cnt != 1:
            X = max(X,x_plus_l[i])
    i += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n = int(input())
x_l = [0]*n
x_plus_l = [0]*n
# 左端から貪欲に埋めることができる
# 証明：f(x)をx以降に最大で残せる数とすると、現時点の可動域の右端をXとして　Xi<Xj の時、f(xi) >= f(xj)がそれまでの選び方によらず成り立つから
# つまり、X< xi-liとなるiの中でxi+liがminを選べば良い
# xi+Liでソートして毎回2分探索するとO(nlogn)で終わる => xi-liはソートされてないので2分探索できない
# xi-liでソートして、X以上の要素に対して、順番に X = max(X,xi+li)として更新し、
# X > Xi-Li になったらcnt += 1 し、その時点でXは確定する、と言うように尺取的なことをすると、
# ロボットを通過するのは各ロボットに対し、一度しかないのでO(n)でいける
# 変数：X,cnt
for i in range(n):
    x,l = map(int,input().split())
    x_l[i] = x-l
    x_plus_l[i] = x+l
x_l,x_plus_l = zip(*sorted(zip(x_l,x_plus_l)))
cnt = 1# 初期点は左端
i = 0#0から順番に見て行く
X = min(x_plus_l)#初期化 はx+l のmin
#print(X,x_l,x_plus_l)
while i < n:# nになったら全点を探索しているので終了
    if x_l[i] < X: pass
    elif x_l[i] >= X:
        cnt += 1
        #print(i,cnt)
    else:
        #print(i,X,cnt)
        X = max(X,x_plus_l[i])
    #print(i,X,cnt)
    i += 1
print(cnt)



"""
#print(x,l)
x,l = zip(*sorted(zip(x,l)))
#print(x,l)
break_flag = 1
cnt = 0
right = -(10**9+1)
i = 0
while break_flag:
    next_rihgt = 10**9+1
    cnt += 1
    while True:
        if right <= x[i] - l[i]:
            if next_rihgt > x[i]+l[i]:
                #print(i,cnt,right,next_rihgt)
                next_rihgt = x[i]+l[i]
        if next_rihgt < x[i]:#もう更新の目はないので
            #print(i,cnt,right,next_rihgt)
            #cnt += 1
            right = next_rihgt
            if i == n: break_flag = 0
            break
        i += 1
        if i == n: 
            break_flag = 0
            #cnt += 1
            break
print(cnt)"""

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    n = int(input())
    robot = list()
    for i in range(n):
        robot.append(list(map(int, input().split())))

    robot.sort()

    ans = 0
    arm_pos = -10**9 - -1
    for r in robot:
        if r[0] - r[1] >= arm_pos:
            ans += 1
            arm_pos = r[0] + r[1]

    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

dic = {}
for n in range(N):
    x, l = map(int, input().split())
    d = {x:l}
    dic.update(d)

ran = []
re = dic
for d in list(dic):
    if ran != []:
        if (ran[0]<d-dic[d]<ran[1]) or (ran[0]<d+dic[d]<ran[1]):
            re.pop(d)
            ran = []
    else:
        ran.append(d-dic[d])
        ran.append(d+dic[d])

print(len(re))

Submission status: Wrong Answer

Solution code:
N = int(input())

dic = {}
for n in range(N):
    x, l = map(int, input().split())
    d = {x:l}
    dic.update(d)

ran = []
re = dic
for d in list(dic):
    if ran != []:
        if (ran[0]<d-dic[d]<ran[1]) or (ran[0]<d+dic[d]<ran[1]):
            dic.pop(d)
            ran = []
    else:
        ran.append(d-dic[d])
        ran.append(d+dic[d])

print(len(dic))

Submission status: Wrong Answer

Solution code:
N = int(input())

dic = {}
for n in range(N):
    x, l = map(int, input().split())
    d = {x:l}
    dic.update(d)

ran = []
re = dic
for d in list(dic):
    if ran != []:
        if (ran[0]< d-dic[d] < ran[1]) or (ran[0]<d+dic[d]<ran[1]):
            re.pop(d)
            ran = []
    else:
        ran.append(d-dic[d])
        ran.append(d+dic[d])

print(len(dic))

Submission status: Wrong Answer

Solution code:
def main():
    robot = int(input())
    right_lim = 0
    answer = 1
    robot_info = [tuple(map(int, input().split())) for _ in range(robot)]
    robot_info = sorted(robot_info, key=lambda x: x[0])
    for i in range(robot):
        coordinate, arm_length = robot_info[i]
        if i == 0:
            right_lim = coordinate + arm_length - 1
        elif right_lim <= coordinate - arm_length:
            answer += 1
            right_lim = coordinate + arm_length - 1
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(input())
    X = []
    for i in range(N):
        xx, ll = map(int, input().split())
        X.append((xx-ll, xx+ll))
    X.sort()
    count = 0
    cur = -float('inf')
    for i in range(N):
        c, d = X[i]
        if cur <= c:
            count += 1
            cur = d
    return count

print(solve())

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(input())
    X = []
    for i in range(N):
        xx, ll = map(int, input().split())
        X.append((xx-ll, xx+ll))
    X.sort()
    count = 0
    cur = -(10**9)
    for i in range(N):
        c, d = X[i]
        if cur <= c:
            count += 1
            cur = d
    return count

print(solve())

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(input())
    X = []
    for i in range(N):
        xx, ll = map(int, input().split())
        X.append((xx-ll, xx+ll))
    X.sort()
    count = 0
    cur = -(10**5)
    for i in range(N):
        c, d = X[i]
        if cur <= c:
            count += 1
            cur = d
    return count

print(solve())

Submission status: Wrong Answer

Solution code:
num = int(input())
robots = []
for i in range(num):
  a, b = map(int, input().split())
  robots.append([a-b, a+b])
robots.sort()

now = robots[0][1]
cnt = 1
for i in range(1, len(robots)):
  if now <= robots[i][0]:
    cnt += 1
    now = robots[i][1]
print(cnt)

Submission status: Wrong Answer

Solution code:
num = int(input())
robots = []
for i in range(num):
  a, b = map(int, input().split())
  robots.append([a-b, a+b])
robots.sort()
print(robots)
now = robots[0][1]
cnt = 1
for i in range(1, len(robots)):
  if now <= robots[i][0]:
    cnt += 1
    now = robots[i][1]
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[]
for i in range(n):
  x,y=map(int,input().split())
  l.append([x-y+1,x+y-1])
count=0
l=sorted(l)
l=l[::-1]
count+=1
now=l[0][0]
for i in range(1,n):
  if now>l[i][1]:
    now=l[i][0]
    count+=1
  else:
    pass
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
for i in range(n):
    x,l=map(int,input().split())
    a.append([x,l])
a=sorted(a,key=lambda x: x[1])
ans=n
t=a[0][1]
for i in range(1,n):
    if t>a[i][0]:
        ans-=1
    else:
        t=a[i][1]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
for i in range(n):
  x,l=map(int,input().split())
  a.append([max(0,x-l),x+l])
a.sort()
r=0
c=0
for i in range(n):
  if a[i][0]>=r:
    r=a[i][1]
    c+=1
print(c)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
data = []
for i in range(N):
    X,L = [int(x) for x in stdin.readline().rstrip().split()]
    data.append((X-L,X+L))

ans = 0
left = -10**9-1
for j,k in sorted(data):
    if j >= left:
        left = k
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
class robot:
  def __init__(self,x,l):
    self.x=x
    self.l=l
    self.s = x-l
    self.t = x+l
    
N = int(input())
robots=[]
max_reach = -100

for i in range(N):
  x,l = list(map(lambda x:int(x),input().split()))
  robots.append(robot(x,l))

robots_s = sorted(robots, key=lambda x:x.t)

#print([r.t for r in robots_s])
count=0

for r in robots_s:
  #print(r.s,r.t)
  if r.s>=max_reach:
    max_reach = r.t
    count+=1
    #print(r.x)

print(count)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
robot = []
for i in range(n):
    x, l = map(int,input().split())
    robot.append([x - l, x + l]) #left, right
robot.sort()
preright = robot[0][0]
ans = 0
for i in range(n):
    left = robot[i][0]
    #print(preright, left)
    if preright <= left:
        ans += 1
        preright = robot[i][1]
print(ans)

Submission status: Wrong Answer

Solution code:
import copy
import sys
inf = sys.maxsize // 2
n = int(input())
robot = []
for i in range(n):
    x, l = map(int,input().split())
    robot.append([x - l, x + l]) #left, right
robot.sort()
preright = -inf
ans = 0
for i in range(n):
    left = robot[i][0]
    if preright <= left:
        ans += 1
        preright = robot[i][1]
print(ans)

Submission status: Wrong Answer

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

cnt = 0
right = float("-inf")

l.sort()

for i in l:
    if right <= i[0]-i[1]:
        cnt += 1
        right = i[0]+i[1]

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

#改行入力 X,Y
L = [[0,0,0,0] for i in range(N)]
t=-1*(10**9)
s=0
for i in range(N):
    L[i][0],L[i][1] = map(int,input().split())
    L[i][2]=L[i][0]+L[i][1]
    L[i][3]=L[i][0]-L[i][1]

L=sorted(L)

for i in range(N):
    if(t<=L[i][3]):
        s+=1
        t=L[i][2]

print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())

#改行入力 X,Y
L = [[0,0,0,0] for i in range(N)]
t=-1*(10**9)
s=0
for i in range(N):
    L[i][0],L[i][1] = map(int,input().split())
    L[i][2]=L[i][0]+L[i][1]
    L[i][3]=L[i][0]-L[i][1]

L=sorted(L)

for i in range(N):
    if(t>L[i][3]):
        continue
    else:
        s+=1
        t=L[i][2]


print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = [0]*N
L = [0]*N

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


indexes = [i for i in range(N)]
sorted_indexes = sorted(indexes, key=lambda i: X[i])

count = 0
length = -10**10
for i in range(N):
    if X[sorted_indexes[i]] - L[sorted_indexes[i]] >= length:
        count += 1
        length = X[sorted_indexes[i]] + L[sorted_indexes[i]]

print(count)

Submission status: Wrong Answer

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

indexes = [i for i in range(N)]
sorted_indexes = sorted(indexes, key=lambda i: X[i])

count = 0
length = -10**10
for i in range(N):
    if length <= X[sorted_indexes[i]] - L[sorted_indexes[i]]:
        count += 1
        length = X[sorted_indexes[i]] + L[sorted_indexes[i]]

print(count)