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:
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])  # 終端を昇順ソート
# print(robots)
cnt = 0
last = -10**18  # 最初、最右のものははるか左側にあると考える
for left, right in robots:
    if left+1 > last-1:  # 残せるのであれば
        cnt += 1
        last = right
print(cnt)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
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], x[0]])  # 終端を昇順ソート
# print(robots)
rm = 0
rightest_point = robots[0][1] - 1
for i in range(1, N):
    if robots[i][0] + 1 > rightest_point:  # 被っていないから残せる
        rightest_point = robots[i][1] - 1
    else:
        rm += 1
print(N-rm)

Submission status: Wrong Answer

Solution code:
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])  # 終端を昇順ソート
# print(robots)
rm = 0
rightest_point = robots[0][1] - 1
for i in range(1, N):
    if robots[i][0] + 1 > rightest_point:  # 被っていないから残せる
        rightest_point = robots[i][1] - 1
    else:
        rm += 1
print(N-rm)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
n=int(input())
points = []
for _ in range(n):
  X,L = map(int,input().split())
  points.append([X+L, X -L])
points.sort(key = lambda x: x[0])
cur = -10*9
answer = 0
for point in points:
  if point[1] >= cur:
    answer += 1
    cur = point[0]
print(answer)

Submission status: Wrong Answer

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

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

cnt = 1
p = R[0][1]

for r in R[1:]:
    if p <= r[0]:
        cnt += 1
        p = r[1]

print(cnt)

Submission status: Wrong Answer

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

for _ in range(N):
    x, l = map(int, input().split())
    s = x - l + 1
    l = x + l - 1
    R.append((s, l))
    
R.sort(key = lambda r:r[0])

cnt = 1
p = R[0][1]

for r in R[1:]:
    if p < r[0]:
        cnt += 1
        p = r[1]

print(cnt)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    xl = sorted([LI() for _ in range(n)], key=lambda x: [sum(x), x])
    r = 0
    c = -inf
    d = -inf
    for x,l in xl:
        if x >= c and x-l >= d:
            r += 1
            c = x+l
            d = x

    return r


print(main())

Submission status: Wrong Answer

Solution code:
# Keyence 2020 B
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n=ni()
l=[]
for i in range(n):
    a,b=nm()
    l.append([a+b,a-b])
l.sort(key=lambda x:x[0])

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

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    xl = sorted([LI() for _ in range(n)], key=lambda x: sum(x))
    r = 0
    c = -inf
    for x,l in xl:
        if x >= c:
            r += 1
            c = x+l

    return r


print(main())

Submission status: Wrong Answer

Solution code:
# Keyence 2020 B
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n=ni()
l=[]
for i in range(n):
    a,b=nm()
    l.append([a+b,a-b])
l=sorted(l,key=lambda x:x[0])

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

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
R = []
for i in range(N):
  R += map(int, input().split())
R = np.array(R).reshape(N,2)

cnt = 0
for i in range(0,N-1,2):
  if np.abs(R[i+1,0] - R[i,0]) < (R[i+1,1] + R[i,1]):
    cnt += 1
print(N - cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
A.sort(key=lambda x:x[0])
X = []
L = []
for l in A:
    X.append(l[0])
    L.append(l[1])

pl = X[0] + L[0]
k = 0
for i in range(1, N):
    pr = X[i] - L[i]
    if pl > pr:
        k += 1
    else:
        pl = min(pl, X[i] + L[i])


print(N - k)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
A.sort(key=lambda x:x[0])
X = []
L = []
for l in A:
    X.append(l[0])
    L.append(l[1])

pl = X[0] + L[0]
k = 0
for i in range(1, N):
    pr = X[i] - L[i]
    if pl > pr:
        k += 1
    else:
        pl = min(pl, X[i] + L[i])

pr = X[N - 1] - L[N - 1]
t = 0
for i in range(N - 2, -1, -1):
    pl = X[i] + L[i]
    if pl > pr:
        t += 1
    else:
        pr = X[i] - L[i]

print(max(N - k, N - t))

Submission status: Wrong Answer

Solution code:
# Keyence 2020 B
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n=ni()
l=[]
for i in range(n):
    x,y=nm()
    l.append([x+y,x-y])
l=sorted(l,key=lambda x:x[0])

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

Submission status: Wrong Answer

Solution code:
a = int(input())
A = []
for i in range(a):
    x,L = map(int,input().split())
    A.append([x+L,x,L])
A.sort()
# print(l)
res = 0
t = A[0]
for i in range(1,a):
    l = A[i]
    # print(t,l)
    if t[0] < l[0] :
        if l[1]-l[2]<t[0]<l[0]:
            res+=1
        else:
            t = l
    elif t[0] > l[0]: 
        if l[1]-l[2]<t[1]-t[2]<l[0]:
            res+=1
        else:
            t = l
print(a - res)

Submission status: Wrong Answer

Solution code:
n = int(input())

import numpy as np

i_list = np.zeros((2,n), dtype = int)

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

# print(np.argsort(i_list[0,:]))

i_list_sorted = i_list[:, np.argsort(i_list[0, :])]

# print(i_list_sorted)

ans = 1
x = i_list_sorted[0, 0]
l = i_list_sorted[1, 0]
l_max = x + l 

for i in range(1, n):
  x = i_list_sorted[0, i]
  l = i_list_sorted[1, i]
  if x - l + 1 > l_max:
    ans+=1
    l_max = x + l 
 
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
b=[]
for i in a:
	ma=i[0] + i[1]
	mi=i[0] - i[1]
	c=[mi,ma]
	b.append(c)


while True:
	count=[]
	for i in range(n):
		count.append(0)
	p=0
	for i in b:
		p+=1
		for j in b[p-1:]:
			if i==j:
				continue
			if i[0]<j[0]<i[1] or i[0]<j[1]<i[1]:
				count[p-1]+=1
	del b[count.index(max(count))]
	n-=1
	if sum(count)==0:
		break

print(len(count))

Submission status: Wrong Answer

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

lr = []
for i in range(n):
    l = max(xl[i][0] - xl[i][1], 0)
    r = max(xl[i][0] + xl[i][1], 0)
    lr.append([l, r])

lr = sorted(lr)
keep = [True] * n

cur = lr[0][1]
for i in range(1, n):
    if lr[i][0] < cur < lr[i][1]:
        keep[i] = False
    else:
        cur = lr[i][1]

ans = sum(keep)
print(ans)

Submission status: Wrong Answer

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

lr = []
for i in range(n):
    l = max(xl[i][0] - xl[i][1], 0)
    r = max(xl[i][0] + xl[i][1], 0)
    lr.append([l, r])

lr = sorted(lr)
keep = [False] * n

cur = 0
for i in range(n):
    if cur >= lr[i][0]:
        keep[i] = True
        cur = lr[i][1]

ans = sum(keep)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[]
for i in range(n):
    a,b=map(int,input().split())
    l.append([a-b+1,a+b])
l.sort(key=lambda x: x[1])
ans=1
nl=l[0][0]
nr=l[0][1]
for i in range(1,n):
    if l[i][0]<nr:
        continue
    else:
        nr=l[i][1]
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
def main():
    n = int(input())
    inputs = [input().split() for i in range(n)]
    inputs_list = []
    for i in inputs:
        if int(i[0]) - int(i[1]) < 0:
            inputs_list.append([0, int(i[0]) + int(i[1])])
        else:
            inputs_list.append([int(i[0]) - int(i[1]), int(i[0]) + int(i[1])])
    sorted_data = sorted(inputs_list, key=lambda x: (x[1]))

    ans = [sorted_data[0]]
    cur = ans[0][1]
    for i in range(len(sorted_data) - 1):
        print(cur, sorted_data[i + 1][0])
        if cur <= sorted_data[i + 1][0]:
                ans.append(sorted_data[i + 1])
                cur = sorted_data[i + 1][1]
    print(len(ans))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

lr = []
for i in range(n):
    l = max(xl[i][0] - xl[i][1], 0)
    r = max(xl[i][0] + xl[i][1], 0)
    lr.append([l, r])

lr = sorted(lr)
keep = [False] * n
#print(lr)

cur = 0

for i in range(n):
    if cur <= lr[i][0]:
        keep[i] = True
        cur = lr[i][1]

'''
for j in range(n - 1):
    if keep[j]:
        if lr[j][0] == lr[j + 1][0]:
            keep[j + 1] = False
        elif lr[j][0] < lr[j + 1][0] < lr[j][1]:
            keep[j + 1] = False
'''
#print(keep)
ans = sum(1 for x in range(n) if keep[x])
print(ans)

Submission status: Wrong Answer

Solution code:
import sys


def main():
    input = sys.stdin.readline
    N = int(input())

    robots = dict()
    inversed = dict()

    for i in range(N):
        x, arm = map(int, input().split())
        right = x+arm
        robots[x] = right
        inversed[right] = x

    orderd_r = sorted(inversed.keys())
    order = [inversed[r] for r in orderd_r]

    count = 0
    last_r = -10**10
    for x in order:
        r = robots[x]
        l = x - (r - x)
        if l < last_r:
            count += 1
        else:
            last_r = r

    print(N - count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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 = 0
tmp = -10**9

for s, t in ll:
  if s >= tmp:
    ans += 1
    tmp = t

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
def main():
    n = int(input())
    inputs = [input().split() for i in range(n)]
    inputs_list = []
    for i in inputs:
        if int(i[0]) - int(i[1]) < 0:
            inputs_list.append([0, int(i[0]) + int(i[1])])
        else:
            inputs_list.append([int(i[0]) - int(i[1]), int(i[0]) + int(i[1])])
    sorted_data = sorted(inputs_list, key=lambda x: (x[1]))

    ans = [sorted_data[0]]
    max = ans[0][1]
    for i in range(len(sorted_data) - 1):
        if max <= sorted_data[i + 1][0] or max >= sorted_data[i + 1][1]:
                ans.append(sorted_data[i + 1])
                max = sorted_data[i + 1][1]
    print(len(ans))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
r = [list(map(int, input().split())) for _ in range(N)]
a = []
for i in r:
    a.append((i[0]-i[1],i[0]+i[1]))
a.sort(key=lambda x:x[1])
ans = 0
cur = -float('inf')
for i in a:
    if i[0] < cur:
        continue
    ans += 1
    cur = i[1]
print(a)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
r = [list(map(int, input().split())) for _ in range(N)]
a = []
for i in r:
    a.append((i[0]+i[1],i[0]-i[1]))
a.sort()
ans = 0
cur = a[0][0]
for i in a:
    if i[1] < cur:
        continue
    ans += 1
    cur = i[0]
print(ans)

Submission status: Wrong Answer

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

lr = []
for i in range(n):
    l = max(xl[i][0] - xl[i][1], 0)
    r = max(xl[i][0] + xl[i][1], 0)
    lr.append([l, r])

lr = sorted(lr)
keep = [True] * n

for j in range(n - 1):
    if keep[j]:
        if lr[j][0] == lr[j + 1][0] or lr[j][1] == lr[j + 1][1]:
            keep[j + 1] = False
        elif lr[j][0] < lr[j + 1][0] < lr[j][1]:
            keep[j + 1] = False

ans = sum(1 for x in range(n) if keep[x])
print(ans)

Submission status: Wrong Answer

Solution code:
import math
def main():
    N = int(input())
    robo = []

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

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


    #print(robo)

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

    print(ans)




    return 0

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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
    if s > right:
        right = t
        ans += 1
print(ans)

Submission status: Wrong Answer

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+1, x+l-1
    if s >= right:
        right = t
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
lo=[]
sh=[]

result=0

MAX = -10000000000

for i  in range(n):
    xx,ll=map(int, input().split())
    lo.append(xx+ll)
    sh.append(xx-ll)
    

c=zip(sh,lo)
d=sorted(c)

for i in range(n):
    if d[i][0] >= MAX:
        result+=1
        MAX=d[i][1]

print(result)

Submission status: Wrong Answer

Solution code:
N=int(input())
grid=[]
for i in range(N):
    xi,li=map(int,input().split())
    grid.append((xi-li,xi+li))
grid = sorted(grid)
res=1
cur=grid[0]

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
A.sort(key=lambda x:x[0])
X = []
L = []
for l in A:
    X.append(l[0])
    L.append(l[1])

pl = X[0] + L[0]
k = 0
for i in range(1, N):
    pr = X[i] - L[i]
    if pl > pr:
        k += 1
    else:
        pl = X[i] + L[i]

pr = X[N - 1] - L[N - 1]
t = 0
for i in range(N - 2, -1, -1):
    pl = X[i] + L[i]
    if pl > pr:
        t += 1
    else:
        pr = X[i] - L[i]

print(max(N - k, N - t))

Submission status: Wrong Answer

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


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


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def f(A):
    min_num = A[0] + A[-1]


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 l: l[1])

    print(R)
    res = 0
    T = None    
    for r in R:
        if T is None or r[0] >= T:
            T = r[1]
            res += 1

    print(res)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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
s = -1e9
for x,l in XL:
    t = x+l-1
    if s <= right:
        right = t
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
A.sort(key=lambda x:x[0])
X = []
L = []
for l in A:
    X.append(l[0])
    L.append(l[1])

pl = X[0] + L[0]
k = 0
for i in range(1, N):
    pr = X[i] - L[i]
    if pl > pr:
        k += 1
    else:
        pl = X[i] + L[i]
print(N - k)

Submission status: Wrong Answer

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+1, x+l-1
    if s >= right:
        right = t
        ans += 1
print(ans)

Submission status: Wrong Answer

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

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

leave = []
for i in range(N):
    if len(list([leave_ for leave_ in leave if leave_[0] + leave_[1] < P[i][0] - P[i][1]])) == 0:
        leave.append(P[i])
    else:
        continue

print(len(leave))

Submission status: Wrong Answer

Solution code:
n=int(input())
lo=[]
sh=[]

result=n


for i  in range(n):
    xx,ll=map(int, input().split())
    lo.append(xx+ll)
    sh.append(xx-ll)
    

c=zip(sh,lo)
d=sorted(c)

for i in range(n-1):
    if d[i+1][0] == -1:
        break
    if d[i+1][0] < d[i][1]:
        result-=1
        del d[i+1]
        tmp=(-1,-1)
        d.append(tmp)

print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
coverd = set()
arms = []
for _ in range(n):
    xi, li = map(int, input().split())
    arms.append((li, xi))

arms = sorted(arms)

for (li, xi) in arms:
    new = set(range(xi - li + 1, xi + li))
    if len(coverd.intersection(new)):
        continue
    ans += 1
    coverd.update(new)

print(ans)

Submission status: Wrong Answer

Solution code:
H = int(input())

_list = []

for i in range(H):
  set = input().split(" ")
  _list.append([int(set[0]) - int(set[1]), int(set[0]) + int(set[1])])

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

ans_list = [new_list[0]]
for i in new_list:
  if i[0] > ans_list[-1][1]:
    ans_list.append(i)
print(len(ans_list))

Submission status: Wrong Answer

Solution code:
n=int(input())

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

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

Solution code:
n=int(input())

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

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

Submission status: Wrong Answer

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=[]
for i in range(n):
    x,l=li()
    a.append([x-l+1,x+l-1])
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
    else:
        c+=1

a.sort(reverse=True)
l,r=a[0][0],a[0][1]
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(l>q):
        l,r=p,q
    else:
        d+=1
print(min(n-c,n-d))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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_right = r
print(ans)

Submission status: Wrong Answer

Solution code:
H = int(input())

_list = []

for i in range(H):
  set = input().split(" ")
  _list.append([int(set[0]) - int(set[1])+1, int(set[0]) + int(set[1])-1])

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

ans_list = [new_list[0]]
for i in new_list:
  if i[0] > ans_list[-1][1]:
    ans_list.append(i)
print(len(ans_list))

Submission status: Wrong Answer

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 = n
pre_r = -float('inf')
for l, r in robots:
    if pre_r <= l:
        ans += 1
        pre_right = r
print(ans)

Submission status: Wrong Answer

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=[]
for i in range(n):
    x,l=li()
    a.append([x-l+1,x+l-1])
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
    else:
        c+=1

a.sort(reverse=True)
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(l>q):
        l,r=p,q
    else:
        d+=1
print(min(n-c,n-d))

Submission status: Wrong Answer

Solution code:
n=int(input())

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

cnt=0
min=-10**9
for r,l in list:
 if min<r:
  cnt+=1
  min=l
print(cnt)

Submission status: Wrong Answer

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]:
    pass
  else:
    temp = min(temp,l[i][0])
    count -= 1
print(count)

Submission status: Wrong Answer

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:
    print(curr, ans, l, r)
    if curr > l:
        continue
    ans += 1
    curr = r
print(ans)

Submission status: Wrong Answer

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][1]
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][1])
    count -= 1
print(count)

Submission status: Wrong Answer

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

P = [[x - l, x, x + l] for x, l in XL]
P.sort(key=lambda x: x[2])

leave = []
for i in range(N):
    # ロボットpiが既に残すと決めたロボットに重ならないことをチェック
    # print('Checking Robot P{}: {}'.format(i, P[i])) 
    if len(list([p for p in leave if p[1] >= P[i][0]])) == 0:
        leave.append(P[i])
        #print(leave)
    else:
        #print('Not Added')
        continue

print(len(leave))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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][1]
count = n
i = 1
for i in range(1,n):
  if temp <= l[i][1]:
    pass
  else:
    temp = min(temp,l[i][1])
    count -= 1
print(count)

Submission status: Wrong Answer

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


class Robot(object):
    def __init__(self, data):
        self.x = int(data[0])
        self.l = int(data[1])
        self.low = self.x - self.l
        self.high = self.x + self.l

    def contain(self, other):
        return self.low < other.low < self.high or self.low < other.high < self.high or self.low < other.x < self.high

    def __str__(self):
        return "(x=%d, l=%d)" % (self.x, self.l)


def main():
    n = int(input())
    robots = [Robot(input().split(" ")) for _ in range(n)]
    robots.sort(key=lambda robo: robo.low)
    available = []
    for robo in robots:
        ok = True
        for r in available:
            if r.contain(robo):
                ok = False
                break
        if ok:
            available.append(robo)
    print(len(available))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N = int(input())
robs = []
ans = []

for i in range(N):
    robs.append(list(map(int,input().split())))

#print(robs)
robs = sorted(robs, key=itemgetter(0))
#print(robs)

ans.append(robs[0])

for i in range(1,len(robs)):
    if ans[-1][0]+ans[-1][1]+robs[i][1]<robs[i][0]:
        ans.append(robs[i])
#print(ans)
print(len(ans))

Submission status: Wrong Answer

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=[]
for i in range(n):
    x,l=li()
    a.append([x-l+1,x+l-1])
a.sort()
l,r=a[0][0],a[0][1]
#print(a)
c=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
    else:
        c+=1
print(n-c)

Submission status: Wrong Answer

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)[1]

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

print(ans)

Submission status: Wrong Answer

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[1]
    print(ans)


if __name__ == '__main__':
    main()