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:
import sys
input = sys.stdin.readline

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

ans = n
mr = xl2[0][0] - 1
for l, r in xl2:
    if l <= mr:
        ans -= 1
    else:
        mr = l

print(ans)

Submission status: Wrong Answer

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

sys.setrecursionlimit(10 ** 7)

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

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

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

array.sort()
# print(array)

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

print(ans)

Submission status: Wrong Answer

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

sys.setrecursionlimit(10 ** 7)

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

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

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

array.sort()
# print(array)

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

print(ans)

Submission status: Wrong Answer

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

sys.setrecursionlimit(10 ** 7)

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

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

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

array.sort()
# print(array)

ans = 0
t = 0
for x, s in array:
    if t < s:
        t = x
        ans += 1

print(ans)

Submission status: Wrong Answer

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

sys.setrecursionlimit(10 ** 7)

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

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

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

array.sort()
# print(array)

ans = 0
t = 0
for x, s in array:
    if t <= s:
        t = x
        ans += 1

print(ans)

Submission status: Wrong Answer

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

sys.setrecursionlimit(10 ** 7)

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

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

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

array.sort()
# print(array)

ans = 0
s = 0
for t, x in array:
    if s <= x:
        s = t
        ans += 1

print(ans)

Submission status: Wrong Answer

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

sys.setrecursionlimit(10 ** 7)

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

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

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

array.sort()
# print(array)

ans = 0
s = 0
for t, x in array:
    if s < x:
        s = t
        ans += 1

print(ans)

Submission status: Wrong Answer

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

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

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

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



    
    

    
resolve()

Submission status: Wrong Answer

Solution code:
import sys

# import re
# import math
# import collections
# import decimal
# import bisect
# import itertools
# import fractions
# import functools
# import copy
# import heapq
# import decimal
# import statistics
# import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 10
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    d = [na() for _ in range(n)]

    query = []

    for i, di in enumerate(d):
        s = di[0] - di[1]
        t = di[0] + di[1]
        query.append((s, 0, i))
        query.append((t, 1, i))

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

    ans = 0
    idx = -1
    for x, st, i in query:
        if st == 1:
            if idx == i:
                idx = -1
        if st == 0:
            if idx == -1:
                idx = i
            else:
                if d[idx][1] > d[i][1]:
                    idx = i
                    ans += 1

    print(n-ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

seen = -10**10
ans = 0
for i in range(n):
  rob = XL[i]
  if seen <= rob[0]+rob[1]:
    seen = rob[0]+rob[1]
    ans += 1

print(ans)

Submission status: Wrong Answer

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

seen = -10**10
ans = 0
for i in range(n):
  rob = XL[i]
  if seen <= rob[0]+rob[1]:
    seen = rob[0]+rob[1]
    ans += 1

print(ans)

Submission status: Wrong Answer

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

seen = -10**10
ans = 0
for i in range(n):
  rob = XL[i]
  if seen > rob[0]-rob[1]:
    ans +=1

  else:
    seen = rob[0]+rob[1]

print(n-ans)

Submission status: Wrong Answer

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

seen = 0
ans = 0
for i in range(n):
  rob = XL[i]
  if i==0:
    seen = rob[0]+rob[1]
  else:
    if seen > rob[0]-rob[1]:
      ans +=1

    else:
      seen = rob[0]+rob[1]

print(n-ans)

Submission status: Wrong Answer

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

drop = []
ans = 0
for i in range(n-1):
  rob = XL[i]
  nrob = XL[i+1]
  if i in drop:
    continue
  if rob[0]+rob[1] > nrob[0]-nrob[1]:
    drop.append(i+1)
    ans += 1

print(n-ans)

Submission status: Wrong Answer

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

cur = -float('inf')

for i in range(N):
    if cur <= robot[i][1]:
        ans += 1
        cur = robot[i][0]

print(ans)

Submission status: Wrong Answer

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

right=Arm[0][0]+Arm[0][1]
for i in range(1,n):
    l=Arm[i][0]-Arm[i][1]
    if not right<=l:
        cnt+=1

    else:
        right=Arm[i][0]+Arm[i][1]

print(n-cnt)

Submission status: Wrong Answer

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

count = n
flag = 0
for i in range(n-1):
    if flag == 1:
        flag = 0
        continue # this machine is removed.
    else:
        left, right, x, l = xl[i]
    if xl[i+1][0] < right: # overlap
        count -= 1 # remove i or i+1
        if xl[i+1][1] <= right: # i includes i+1
            continue # remove i
        else:
            flag = 1
            continue # remove i+1

print(count)

Submission status: Wrong Answer

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

count = n
flag = 0
for i in range(n-1):
    if flag == 1:
        flag = 0
        continue # this machine is removed.
    left, right, x, l = xl[i]
    if xl[i+1][0] < right: # overlap
        count -= 1
        if xl[i+1][1] <= right: # i includes i+1
            continue # remove i
        else:
            flag = 1
            continue # remove i+1

print(count)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy

def trush(XL):
    pt,XL_2 = 1,[XL[0]]
    #まずは特に邪魔な左右両方とぶつかるロボを捨てる
    while pt < len(XL)-1:
        if XL[pt-1][2] > XL[pt][1] and XL[pt][2] > XL[pt+1][1]:
            pass
        else:
            XL_2.append(XL[pt])
        pt += 1
    XL_2.append(XL[len(XL)-1])

    XL = deepcopy(XL_2)
    pt,XL_2 = 0,set()
    while pt < len(XL)-1:
        if XL[pt][2] > XL[pt+1][1]:
            if XL[pt][0]-XL[pt][1] > XL[pt+1][0]-XL[pt+1][1]:
                XL_2.add(XL[pt+1])
            else:
                XL_2.add(XL[pt])
        else:
            XL_2.add(XL[pt])
            XL_2.add(XL[pt+1])
        pt += 1

    return len(XL_2)

def main():
    N = int(input())
    XL = [list(map(int,input().split())) for _ in range(N)]
    for i in range(N):
        XL[i] = (XL[i][0],XL[i][0]-XL[i][1],XL[i][0]+XL[i][1])
    XL.sort(key = lambda x:x[0])

    ans = trush(XL)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
X = []
for i in range(n):
    x, y = map(int, input().split())
    X.append((x - y + 1, x + y))
X.sort(key=lambda x: x[1])
ter = -10**10
cnt = 0
for left, right in X:
    if ter <= left:
        ter = right
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
X = []
for i in range(n):
    x, y = map(int, input().split())
    X.append((x - y + 1, x + y))
X.sort()
ter = -10**10
cnt = 0
for left, right in X:
    if ter <= left:
        ter = right
        cnt += 1
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

lines = []
for i in range(n):
  x,l = map(int,input().split())
  lines.append([x-l,x+l])
lines = sorted(lines)
count = 0
kari = -9999999999999
for i in range(n):
  if lines[i][0] >= kari:
    count += 1
    kari = lines[i][1]
print(count)

Submission status: Wrong Answer

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

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

ans = 1
limit = lst[0][1]
for i in range(n):
  if lst[i][0] > limit:
    ans += 1
    limit = lst[i][1]

print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
	n = int(input())
	robots = [list(map(int, input().split())) for _ in range(n)]
	robots.sort(key=lambda x: x[0])
	t = robots[0][0] + robots[0][1] - 1
	a = n
	for i in range(1, n):
		if t < robots[i][0] - robots[i][1]:
			t = robots[i][0] + robots[i][1] - 1
		else:
			a -= 1
	print(a)
resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
	n = int(input())
	robots = [list(map(int, input().split())) for _ in range(n)]
	robots.sort(key=lambda x: x[0])
	t = robots[0][0] + robots[0][1]
	a = n
	for i in range(1, n):
		if t > robots[i][0] - robots[i][1]:
			a -= 1
		else:
			t = robots[i][0] + robots[i][1]
	print(a)
resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
	n = int(input())
	robots = [list(map(int, input().split())) for _ in range(n)]
	robots.sort(key=lambda x: x[0])
	t = robots[0][0] + robots[0][1]
	for i in range(1, n):
		if t > robots[i][0] - robots[i][1]:
			n -= 1
		else:
			t = robots[i][0] + robots[i][1]
	print(n)
resolve()

Submission status: Wrong Answer

Solution code:
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7

    N = II()
    robots = [0]*N
    for i in range(N):
        x, l = map(int,input().split())
        left = x-l
        right = x+l
        robots[i]=(right,left)
    robots.sort()
    dbg(robots)
    prev_right = robots[0][0]
    isPrevRemained = True
    ans = 1
    for i in range(1,N):
        if robots[i][1] < prev_right and isPrevRemained:
            isPrevRemained = False
        else:
            isPrevRemained = True
            prev_right = robots[i][0]
            ans += 1
    print(ans)



    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7

    N = II()
    robots = [0]*N
    for i in range(N):
        x, l = map(int,input().split())
        left = x-l
        right = x+l
        robots[i]=(left,right)
    robots.sort()
    dbg(robots)
    prev_right = robots[0][1]
    isPrevRemained = True
    ans = 1
    for i in range(1,N):
        if robots[i][0] < prev_right and isPrevRemained:
            isPrevRemained = False
        else:
            isPrevRemained = True
            prev_right = robots[i][1]
            ans += 1
    print(ans)



    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
import functools
import math
import scipy
import fractions
import itertools

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

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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()
ans,nl=1,xl[0][1]
for r,l in xl[1:]:
    if l>=nl:
        ans+=1
        nl=r
    else:
        continue
print(ans)

Submission status: Wrong Answer

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

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

ans = 0
st = lst[0][0]
for _ in lst:
    if not _[0] < st < _[1]:
        st = _[1]
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [list(map(int,input().split())) for _ in range(n)]
#print(A)
A = sorted(A, key = lambda x:x[0])
#print(A)
now = A[0][0] + A[0][1]
cnt = 1
for i in range(1,n):
    if now <= A[i][0] - A[i][1]:
        #print(A[i][0],A[i][1])
        now = A[i][0] + A[i][1]
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [list(map(int,input().split())) for _ in range(n)]
#print(A)
A = sorted(A, key = lambda x:x[0])
#print(A)
now = 0
cnt = 0
for i in range(n):
    if now < A[i][0]:
        now = A[i][0] + A[i][1]
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a-b, a+b])
ab = sorted(ab, key=lambda x: x[1])

right_reach = ab[0][1]

count = 0

for i in range(1,n):
    if ab[i][0] < right_reach:
        count += 1
        right_reach = min(right_reach, ab[i][1])
print(n-count)

Submission status: Wrong Answer

Solution code:
n=int(input())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
ab = sorted(ab, key=lambda x: x[0])

right_reach = ab[0][0]+ab[0][1]

count = 0

for i in range(1,n):
    if ab[i][0]-ab[i][1] < right_reach:
        count += 1
        right_reach = min(right_reach, ab[i][0]+ab[i][1])
print(n-count)

Submission status: Wrong Answer

Solution code:
n=int(input())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
ab = sorted(ab, key=lambda x: x[0])

right_reach = ab[0][0]+ab[0][1]

count = 0

for i in range(1,n):
    if ab[i][0]-ab[i][1] < right_reach:
        count += 1
        right_reach = min(right_reach, ab[i][0]-ab[i][1])
print(n-count)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n = int(input())
    robots = []
    for i in range(n):
        x, l = map(int, input().split())
        robots.append((x, l, x - l, x + l))
    robots = sorted(robots, key=lambda x: x[2])
    ans = []
    for i in range(n):
        if i == 0:
            ans.append(robots[i][3])
        else:
            if robots[i][2] >= ans[-1]:
                ans.append(robots[i][3])
    print(len(ans))

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n = int(input())
    robots = []
    for i in range(n):
        x, l = map(int, input().split())
        robots.append((x, l, x + l))
    robots = sorted(robots, key=lambda x: x[2])
    ans = []
    for i in range(n):
        if i == 0:
            ans.append(robots[i][2])
        else:
            if robots[i][0] >= ans[-1]:
                ans.append(robots[i][2])
    print(len(ans))

Submission status: Wrong Answer

Solution code:
N=int(input())
XL=[list(map(int,input().split())) for _ in range(N)]
XL.sort()
X=[]
L=[]
for h in range(N):
    X.append(XL[h][0])
    L.append(XL[h][1])
if N==1:
    print(1)
else:
    if abs(X[0]-X[1])>=L[0]+L[1]:
        NG=[0]
    else:
        NG=[1]
    i=1
    while i<N-1:
        if abs(X[i-1]-X[i])>=L[i-1]+L[i] and abs(X[i]-X[i+1])>=L[i]+L[i+1]:
            NG.append(0)
            i+=1
        else:
            NG.append(1)
            NG.append(1)
            i+=2
    if len(NG)<N:
        if abs(X[-2]-X[-1])>=L[-2]+L[-1]:
            NG.append(0)
        else:
            NG.append(1)

    ans=N
    j=0
    while j<N:
        if NG[j]==1:
            k=0
            while j+k<N and NG[j+k]==1:
                NG[j+k]=k%2
                ans-=k%2
                k+=1
            j+=k
        else:
            j+=1

    print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
X=[]
L=[]
for _ in range(N):
    x,l=map(int,input().split())
    X.append(x)
    L.append(l)
if N==1:
    print(1)
else:
    if abs(X[0]-X[1])>=L[0]+L[1]:
        NG=[0]
    else:
        NG=[1]
    i=1
    while i<N-1:
        if abs(X[i-1]-X[i])>=L[i-1]+L[i] and abs(X[i]-X[i+1])>=L[i]+L[i+1]:
            NG.append(0)
            i+=1
        else:
            NG.append(1)
            NG.append(1)
            i+=2
    if len(NG)<N:
        if abs(X[-2]-X[-1])>=L[-2]+L[-1]:
            NG.append(0)
        else:
            NG.append(1)

    ans=N
    j=0
    while j<N:
        if NG[j]==1:
            k=0
            while j+k<N and NG[j+k]==1:
                NG[j+k]=k%2
                ans-=k%2
                k+=1
            j+=k
        else:
            j+=1

    print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N = int(input())

X = []
L = []

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

xl = sorted([(X[i],L[i]) for i in range(N)], key = itemgetter(1))

ans = 0
last = 0

for i in range(N):
    if last <= xl[i][0]:
        ans += 1
        last = xl[i][1]

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
ans=N
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:
        ans-=1
        R[i+1]=R[i]
print(ans)

Submission status: Wrong Answer

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

pre = 0
cnt = 0
for x, l in xl:
    if pre == 0:
        pre = x + l
        continue

    if x - l < pre and pre < x + l:
        cnt += 1
    elif x + l < pre:
        cnt += 1
        pre = x + l
    else:
        pre = x + l

print(n - cnt)

Submission status: Wrong Answer

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

pre = 0
cnt = 0
for x, l in xl:
    if pre == 0:
        pre = x + l
        continue

    if x - l < pre:
        cnt += 1
    else:
        pre = x + l

pre = 0
cnt1 = 0
xl = xl[::-1]
for x, l in xl:
    if pre == 0:
        pre = x - l
        continue

    if x + l > pre:
        cnt += 1
    else:
        pre = x - l

cnt = min(cnt, cnt1)
print(n - cnt)

Submission status: Wrong Answer

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

pre = 0
cnt = 0
for x, l in xl:
    if pre == 0:
        pre = x + l
        continue

    if x - l < pre:
        cnt += 1
    else:
        pre = x + l


print(n - cnt)

Submission status: Wrong Answer

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


pre = 0
cnt = 0
for x, l in xl:
    if pre == 0:
        pre = x + l
        continue

    if x - l < pre:
        cnt += 1
    else:
        pre = x + l

pre = 0
cnt1 = 0
xl = xl[::-1]
for x, l in xl:
    if pre == 0:
        pre = x + l
        continue

    if x - l > pre:
        cnt += 1
    else:
        pre = x + l

cnt = min(cnt, cnt1)
print(n - cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
nums = [list(map(int, input().split())) for _ in range(N)]
for row in nums:
  row.append(row[0]+row[1])
  row.append(row[0]-row[1])

nums.sort(key=lambda x: x[2])
ans = N

point = nums[0][2]
for j in range(N-1):
  if nums[j+1][3] < point:
    ans -= 1
  else:
    point = nums[j][2]
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
nums = [list(map(int, input().split())) for _ in range(N)]
for row in nums:
  row.append(row[0]+row[1])
  row.append(row[0]-row[1])
print(nums)

nums.sort(key=lambda x: x[2])
ans = N

point = nums[0][2]
for j in range(N-1):
  if nums[j+1][3] < point:
    ans -= 1
    print(nums[j+1][3], nums[j][2])
  else:
    point = nums[j][2]
print(ans)

Submission status: Wrong Answer

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

XLdic={}
XLe=[]
for i in XL:
    XLe.append(i[0]+i[1])
    XLdic[str(i[0]+i[1])]=i[0]-i[1]

XLe.sort()

cou=0
ne=-float("inf")
for i in XLe:
    if XLdic[str(i)]>=ne:
        ne=i
        cou+=1

print(cou)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def main():
    n=int(input())
    xs=[0]*n
    ls=[0]*n
    ranges=[0]*n
    for i in range(n):
        xs[i],ls[i]=map(int,input().split())
        ranges[i]=[xs[i]-ls[i],xs[i]+ls[i]]
    ranges.sort(key=lambda x:x[1])
    count=0
    point=-10000
    for irange in ranges:
        if irange[0]>=point:
            count+=1
            point=irange[1]
    print(count)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n=int(input())
    xs=[0]*n
    ls=[0]*n
    ranges=[0]*n
    for i in range(n):
        xs[i],ls[i]=map(int,input().split())
        ranges[i]=[xs[i]-ls[i],xs[i]+ls[i]]
    ranges.sort(key=lambda x:x[1])
    count=0
    point=-10000
    for irange in ranges:
        if irange[0]>=point:
            count+=1
        point=irange[1]
    print(count)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
arm = []
for n in range(N):
    i, L = map(int, input().split())
    arm.append([i-L, i+L])
sarm = sorted(arm)
pre = -10**10
count = 0
for a in sarm:
    if pre <= a[0]:
        count += 1
        pre = a[1]
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
point = []
arm = {}
for n in range(N):
    i, L = map(int, input().split())
    point.append(i)
    arm[i] = L
sorted_point = sorted(point)
count = 1
pre_point = sorted_point[0]
for n in range(1, len(sorted_point), 1):
    if arm[sorted_point[n]] + arm[pre_point] <= sorted_point[n]-pre_point :
        count += 1
        pre_point = sorted_point[n]
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
ranges = []
for _ in range(n):
    xi, li = map(int, input().split())
    ranges.append((xi - li, xi + li))
ranges = sorted(ranges, key=lambda x: x[1])

ans = 1
j = n - 1
while j >= 0:
    current = ranges[j]

    # 現在のcにかぶっていないものまで飛ばす
    i = j - 1
    while i >= 0 and ranges[i][1] > current[0]:
        i -= 1

    # print(j, i, ranges)

    if i < 0:
        break

    else:
        ans += 1
        j = i

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
XL = [list(map(int,input().split())) for _ in range(N)]
INF = 2*10**9
XL.sort(key = lambda x:x[0])

A = [[-INF,-INF]]
for x,l in XL:
    A.append([x-l,x+l])
A.append([INF,INF])

Dis,A_,dis_left,dis_right = [],[A[0]],0,0
for i in range(1,len(A)-1):
    if A[i-1][1] > A[i][0] and A[i][1] > A[i+1][0]:
         Dis.append(A[i])
    else:
        A_.append(A[i])
A_.append(A[len(A)-1])
A = A_
for i in range(1,len(A)-1):
    if A[i-1][1] > A[i][0]:
        dis_right += 1
    if A[i][1] > A[i+1][0]:
        dis_left += 1

print(len(A)-min(dis_left,dis_right)-2)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np


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


sys.setrecursionlimit(10 ** 9)


def main():
    N = int(input())
    Robot = [list(map(int, input().split())) for _ in range(N)]
    Robot = sorted(Robot, key=lambda x: x[0])
    check = -float("inf")
    cnt = 0
    for r in Robot:
        if (r[0] - r[1]) >= check:
            check = r[0] + r[1]
        else:
            cnt += 1

    print(N - cnt)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
robot = [0]*n
for i in range(n):
  robot[i] = [int(x) for x in input().split()]

robot.sort()

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

Submission status: Wrong Answer

Solution code:
N = int(input())
left = [] 
right = []
for i in range(N):
    x, dis = map(int, input().split(" "))
    left.append(x-dis)
    right.append(x+dis)

left.sort()
right.sort()

cnt = 1
now = -float("inf")
for i in range(N):
    if now <= left[i]:
        cnt += 1
        now = right[i]

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
left = [] 
right = []
for i in range(N):
    x, dis = map(int, input().split(" "))
    left.append(x-dis)
    right.append(x+dis)

left.sort()
right.sort()

cnt = 1
now = -float("inf")
for i in range(N-1):
    if now <= left[i]:
        cnt += 1
        now = right[i]

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
left = [] 
right = []
for i in range(N):
    x, dis = map(int, input().split(" "))
    left.append(x-dis)
    right.append(x+dis)

left.sort()
right.sort()

cnt = 1
for i in range(N-1):
    if right[i] <= left[i+1]:
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
left = [] 
right = []
for i in range(N):
    x, dis = map(int, input().split(" "))
    left.append(x-dis)
    right.append(x+dis)
    
cnt = 1
for i in range(N-1):
    if right[i] <= left[i+1]:
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
left = [] 
right = []
for i in range(N):
    x, dis = map(int, input().split(" "))
    left.append(x-dis)
    right.append(x+dis)
    
cnt = 1
for i in range(N-1):
    if right[i] <= left[i+1]:
        cnt += 1

Submission status: Wrong Answer

Solution code:
N=int(input())
R=sorted([list(map(int,input().split(' '))) for i in range(N)])
ans = 1
now = R[0][0]+R[0][1]
for x,l in R[1:]:
    if now<=x-l:
        ans += 1
        now = x+l
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
XL = [list(map(int,input().split())) for _ in range(n)]
XL = sorted(XL)
xl = [[0]*2 for _ in range(n+1)]
xl[0][0] = -10**9
xl[0][1] = -10**9
for i in range(n):
  xl[i+1][0] = XL[i][0] - XL[i][1]
  xl[i+1][1] = XL[i][0] + XL[i][1]

def dist(bit):
  flg = True
  pre = 0
  for i in range(n):
    if bit & 1<<i and i > 0:
      if xl[pre][1] > xl[i][0]:
        flg = False
      pre = i
  return flg

if dist((1<<(n+1))-1):
  print(n)
  exit()

ans = 0
for bit in range(1<<(n+1)):
  if bit & 1<<n:
    if dist(bit):
      ans = max(ans, sum([1 for i in range(n+1) if bit & 1<<i])-1)
      #print(bin(bit),sum([1 for i in range(n+1) if bit & 1<<i])-1)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
LR = [[0,0] for _ in range(N)]
for i in range(N):
  a,b = map(int, input().split())
  LR.append([a-b,a+b])

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

prev_right = - 10**9 #一つ前の右端
cnt = 0
for i in range(N):
  if LR[i][0]>=prev_right: #次の左端が前の右端以上なら
    cnt += 1
    prev_right = LR[i][1]
  else:
    if LR[i][1]<prev_right:
      prev_right = LR[i][1]

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())

s = [list(map(int,input().split())) for i in range(n)]
s.sort()

stop = s[0][0] + s[0][1]
ans = 1
for i in range(1,n):
    num = s[i][0]
    l = s[i][1]
    if num - l >= stop:
        ans += 1
        stop = num + l

print(ans)