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())
arm_x = {}
for _ in range(N):
    inp = list(map(int, input().split()))
    arm_x[inp[0]] = inp[1]
dic = sorted(arm_x.items(), key=lambda x:x[0])
ans = N
i = 0
while i <N:
    temp = 0
    for j in range(i+1,N):
        if dic[i][0]+dic[i][1]> dic[j][0]-dic[j][1]:
            ans -= 1
            temp += 1
        else:
            break
    i += 1+temp
print(ans)

Submission status: Wrong Answer

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

for i in range(N):
    x,l = list(map(int, input().split()))
    X.append([x,l])
X.sort(key=lambda x:x[0],reverse=False)
# print(X)
ans=N
for i in range(1,N):
    if i>=2 and X[i-2][0]+X[i-2][1]>X[i-1][0]-X[i-1][1]:
        # print('a',i)
        continue

    if X[i-1][0]+X[i-1][1]>X[i][0]-X[i][1]:
        # print('b',i)
        ans-=1

print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N = int(input())
robot_list = []

for i in range(N):
    robot_list.append(list(map(int, input().split())))
    robot_list[i] = (robot_list[i][0] - robot_list[i][1] + 1, robot_list[i][0] + robot_list[i][1] - 1, robot_list[i][0], robot_list[i][1])

sort_robot_list = sorted(robot_list, key=itemgetter(2))

minus_count = 0
for before_value, after_value in zip(sort_robot_list, sort_robot_list[1:]):
    print(before_value)
    print(after_value)
    if before_value[1] >= after_value[0]:
        minus_count += 1

print(len(sort_robot_list) - minus_count)

Submission status: Wrong Answer

Solution code:
n,*t=map(int,open(0).read().split())
*z,=sorted(zip(*[iter(t)]*2))
s=set()
for i in range(n-1):
    if i in s:
        continue
    x,l=z[i]
    y,r=z[i+1]
    if x+l>y-r:
        if y+r<x+l:
            s|={i}
        else:
            s|={i+1}
print(n-len(s))

Submission status: Wrong Answer

Solution code:
import sys

N=input()

X=[]
for _ in range(N):
    x,l=map(int, sys.stdin.readline().split())
    X.append((x-l,x+l))

X.sort(key=lambda x:(x[0],x[1]) )

kouho=set()
ans=0
for i in range(N-1):
    start=X[i][0]
    end=X[i][1]
    next_start=X[i+1][0]
    next_end=X[i+1][1]
    if end<=next_start:
        kouho.add((start,end))
        kouho.add((next_start,next_end))
    elif next_start<=end:
        kouho.add((next_start,next_end))
    elif next_start<end:
        kouho.add((start,end))

print len(kouho)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

import sys
from operator import itemgetter

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

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

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

Submission status: Wrong Answer

Solution code:

class Robot:
    x = 0
    l = 0
    def __init__(self, x, l):
        self.x = x
        self.l = l

    # def __repr__(self):
    #     return f"x:{self.x} l:{self.l}"

N = int(input())
R = []
for n in range(N):
    x, l = list(map(int, input().split()))
    R += [Robot(x, l)]

R.sort(key=lambda r:r.x)

result = 0
last_robot = R[0]
for n in range(len(R) - 1):
    if last_robot.x + R[n].l <= R[n + 1].x:
        # print(f"R[{n}]:{R[n]} R[{n+1}]:{R[n+1]}")
        last_robot = R[n + 1]
        result += 1
    else:
        pass
        # last_robot = R[n]

# print(f"last_robot:{last_robot}")

if last_robot == R[-1] or last_robot == R[0]:
    result += 1

print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
dic = {}

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

dic = sorted(dic.items())
pre = dic[0][0]+dic[0][1]
ans_a = 1

for i in range(n-1):
    if pre <= dic[i+1][0]-dic[i+1][1]:
        pre = dic[i+1][0]+dic[i+1][1]
        ans_a += 1

pre = dic[n-1][0]+dic[n-1][1]
ans_b = 1

for i in reversed(range(1, n)):
    if pre >= dic[i-1][0]+dic[i-1][1]:
        pre = dic[i-1][0]-dic[i-1][1]
        ans_b += 1

print(max(ans_a, ans_b))

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    L = [list(map(int, input().split())) for _ in range(N)]
    tmp = []
    for a, b in L:
        tmp.append([a-b, a+b])
    tmp.sort()
    t = tmp[0][0]- 1
    c = 0

    t2 = tmp[N-1][0]+ 1
    c2 = 0

    for i in range(N):

        if t > tmp[i][0]:
            c += 1
        else:
            t = tmp[i][1]

        if t2 < tmp[(N-1)-i][1]:
            c2 += 1
        else:
            t2 = tmp[(N-1)-i][0]

    print(max(N-c, N-c2))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
x = []
l = []
c = []
d = {}

for i in range(n):
    xx,ll = map(int, input().split())
    d[xx] = ll

    x.append(xx)
    l.append(ll)

dct = sorted(d.items())
ans = 0
f = 0
for i in range(1,n):
    if dct[i][0]-dct[i-1][0] < dct[i][1]+dct[i-1][1]:
        f += 1
    else:
        ans += (f+1)//2
        f = 0

if f != 0:
    ans += (f+1)//2

print(n-ans)

Submission status: Wrong Answer

Solution code:
a = int(input())
fanwei = []

for i in range(a):
    one = input().split()
    one = [int(i) for i in one]
    two = [one[0] - one[1], one[0] + one[1]]
    fanwei.append(two)

fanwei = sorted(fanwei, key=lambda student: 100000000000000000000 * (1 + student[0]) + student[1])

now = -100000000000000000000
ans = 0
for i in fanwei:
    down = i[0]
    if down >= now:
        ans += 1
        now = i[1]

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

lob = []

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

lob.sort()

ans = 0
last = 0
for l in lob:
    if last < l[1]:
        ans += 1
        last = l[0]

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=[list(map(int,input().split())) for i in range(n)]
cnt=0
ans=0
for i in range(n):
    arml=x[i][0]-x[i][1]
    armr=x[i][0]+x[i][1]
    for j in range(i+1,n):
        if arml<x[j][0]+x[j][1] or armr>x[j][0]-x[j][1]:
            cnt+=1
        if cnt>=2:
            ans+=1
            cnt=0
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
dic = {}
s = {}
f = {}
for i in range(n):
    [x,l] = [int(i) for i in input().split()]
    s[i] = x - l
    f[i] = x + l

itv = []
for i in range(n):
    itv.append([f[i],s[i]])
itv.sort()

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

Submission status: Wrong Answer

Solution code:
N = int(input())
pre = None
result = 0
robots = list()
for i in range(N):
    a, b = map(int, input().split())
    robots.append({"X": a, "L": b})
robots.sort(key=lambda x: x['X'])

for x in robots:
    X = x["X"]
    L = x["L"]
    r = X + L
    l = X - L
    if pre is None:
        pre = r
        continue
    if pre > l:
        result += 1
        continue
    pre = r

print(N - result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
data = [[]]*n
for i in range(n):
    x, l = map(int, input().split())
    data[i] = [x-l,x+l]
data.sort()
ans = n
if len(data) == 2:
  if data[0][1] > data[1][0]:
    ans -= 1
for i in range(1, n-1):
    if data[i-1][1] > data[i][0] and data[i][1] > data[i+1][0]:
        ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
inputs = sys.stdin.readlines()

n = int(inputs[0])
Y = []
for s in inputs[1:]:
    x, l = map(int, s.split())
    Y.append((x-l+1, x+l-1))
Y.sort(key=lambda x: x[0])

cnt = 0
skip = [0]*n
for i in range(n):
    if skip[i]:
        continue
    l, r = Y[i]
    for j in range(i+1, n):
        l1, r1 = Y[j]
        if r > l1:
            cnt += 1
            if r < r1:
                skip[j] = 1
                break
            else:
                continue
print(n-cnt)

Submission status: Wrong Answer

Solution code:
T = int(input())
lst = []
for i in range(T):
    lst.append(list(map(int, input().split())))
lst.sort()
keep = 0
last_valid = 0
for z in range(1,T):
    if (lst[z][1] + lst[last_valid][1]) <= ( lst[z][0] - lst[last_valid][0] ):
        keep += 1
        if lst[last_valid][1] + lst[last_valid][0] < lst[z][1] + lst[z][0]:
            last_valid = z
print(keep+1)

Submission status: Wrong Answer

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数

N = iin()
XL = sorted([iln() for _ in range(N)], key=lambda x:x[0])

cnt = 0
prev_R = XL[0][0]+XL[0][1]
for i in range(1, N):
    if prev_R > (XL[i][0]-XL[i][1]):
        cnt += 1
        prev_R = min(prev_R, XL[i][0]+XL[1][1])
    #elif i+1 < N and (XL[i][0]+XL[i][1]) > (XL[i+1][0]-XL[i+1][1]):
        #cnt += 1
    else:
        prev_R = XL[i-1][0]+XL[i-1][1]
print(N-cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())

line = []
ans = 0

for i in range(n):
  x, l = map(int, input().split())
  keep = True
  for j in range(x-l+1, x+l):
    if j in line:
      keep = False
    else:
      line.append(j)
  print(keep)
  if keep == True:
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
xlis=sorted([list(map(int,input().split())) for i in range(n)])
counter=0
nlis=[]
highest=-1000000000000
for i in range(n):
    high=xlis[i][0]+xlis[i][1]
    low=xlis[i][0]-xlis[i][1]
    nlis.append([low,high])
for i in range(n):
    if nlis[i][0]>=highest:
        counter+=1
        highest=nlis[i][1]
print(counter)

Submission status: Wrong Answer

Solution code:
# B - Robot Arms
N = int(input())
a =[list(map(int, input().split())) for i in range(N)]
#print(a)
count  = 0

a.sort()
#print(a)
for i in range(N-1):
    right = a[i][0] + a[i][1]
    left = a[i+1][0] - a[i+1][1]
    if right <= left:
        pass
    else:
        count += 1
        a[i+1][0] = a[i][0]
        a[i+1][1] = a[i][1]
print(N -count)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

length = []
for i in range(N):
    s = XL[i][0] - XL[i][1] + 1
    f = XL[i][0] + XL[i][1] - 1
    length.append([s, f])

length = sorted(length, key=lambda x:x[1])
ans = 0
f = - (10**9+7)
for i in range(N):
    if f < length[i][0]:
        ans += 1
        f = length[i][1]

print(ans)

Submission status: Wrong Answer

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

ES = sorted(ES)

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
d = defaultdict(list)
for i in [0]*N:
    X,L = map(int, input().split(' '))
    d[X-L].append(X+L)
ps = sorted(list(d.items()))
ans = 0
now = -10**10
cand = []
for p, e in ps:
    cand.extend(e)
    if p < now:
        cand.extend(e)
    else: # now <= p
        now = min(cand)
        ans += 1
        cand = []
print(ans)

Submission status: Wrong Answer

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

a.sort()
#print(a)

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

Submission status: Wrong Answer

Solution code:
def solve(x):
    cnt = n
    l = 0
    r = 1
    for i in range(10 ** 9):
        if x[l][0] + x[l][1] > x[r][0] - x[r][1]:
            cnt -= 1
            r += 1
        else:
            l = r
            r = l + 1
        if r > n - 1:
            break
    return cnt


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

if n == 1:
    print(1)
    exit()

print(max(solve(robots), solve(robots[::-1])))

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-1, x-l+1))
    robo = sorted(robo, key = lambda x:x[0])

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

    print(ans)




    return 0

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import bisect
import collections
import sys

input = sys.stdin.readline

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

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

dp = collections.defaultdict(int)
dp[ls[0][1]] = 1

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

Submission status: Wrong Answer

Solution code:

class Robot:
    x = 0
    l = 0
    def __init__(self, x, l):
        self.x = x
        self.l = l

    # def __repr__(self):
    #     return f"x:{self.x} l:{self.l}"

N = int(input())
R = []
for n in range(N):
    x, l = list(map(int, input().split()))
    R += [Robot(x, l)]

R.sort(key=lambda r:r.x)

result = 0
last_robot = R[0]
for n in range(len(R) - 1):
    if last_robot.x + R[n].l <= R[n + 1].x:
        # print(f"R[{n}]:{R[n]} R[{n+1}]:{R[n+1]}")
        last_robot = R[n + 1]
        result += 1
    else:
        last_robot = R[n]

# print(f"last_robot:{last_robot}")

if last_robot == R[-1] or last_robot == R[0]:
    result += 1

print(result)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
xl=[list(map(int,input().split())) for i in range(n)]
ab=[]
for i in range(n):
    x=xl[i][0]
    l=xl[i][1]
    a=x-l
    b=x+l
    ab.append([a,b])
ab.sort(key=lambda x:x[1],reverse=True)
A=ab[0][0]
B=ab[0][1]
cnt=1
for i in range(1,n):
    a=ab[i][0]
    b=ab[i][1]
    if b<=A:
        cnt+=1
        A=a
print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
s = 0
d = 0
hanni = []
for i in range(n):
  a,b = map(int,input().split())
  hanni.append([np.clip(a-b,0,10**9),np.clip(a+b,0,10**9)])
hanni.sort(key=lambda x: x[1])
for i in range(n):
  if s != len(hanni)-1 and hanni[s][1] > hanni[s+1][0]:
    d += 1
    if d>=min(n-2,3):
      del hanni[s]
      d = 0
    else:
      s+=1
  else:
    s+=1
    d = 0
    
print(len(hanni))

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
rs = [list(map(int, input().split())) for _ in range(n)]
rs = np.array(rs)
rs.sort(axis=0)

cnt = 0
reach = None
for i in range(n):
    x, l = rs[i]
    if reach is None:
        reach = x + l
    else:
        if x - l < reach:
            cnt += 1
        else:
            reach = x + l
print(n - cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=sorted([list(map(int,input().split())) for i in range(n)])
ans=0
B,C=[],[]
for j in range(n):
    B.append([A[j][0]-A[j][1],A[j][0]+A[j][1]])

B.append([10**9,0])
i=1
while i<=n-1:
    if B[i][1]>B[i+1][0] or B[i][0]<B[i-1][1]:
        ans +=1
        i +=1
    i +=1

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

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

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

# print(areas)
# print(areas2)

print(len(areas2))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N = int(input())
# XL = sorted([list(map(int, input().split())) for _ in range(N)], key=itemgetter(1, 0))
XL = sorted([list(map(int, input().split())) for _ in range(N)])

res = 0
i, j = 0, 1
while i < N:
    x, l = XL[i]
    if j < N and x + l > XL[j][0] - XL[j][1]:
        if x + l < XL[j][0] + XL[j][1]:
            res += 1
            j += 1
            i += 1
        else:
            j += 1
    else:
        res += 1
    j += 1
    i += 1

print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
xl = []
ans = n
for i in range(n):
    x, l = map(int, input().split())
    xl.append([x, l])
x1 = 0
x2 = 1
xl.sort()
while x2 < n:
    f = xl[x1][0] + xl[x1][1]
    s = xl[x2][0] - xl[x2][1]
    if s < f:
        x2 += 1
        ans -= 1
    else:
        x1 += 1
        x2 += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
X=[]
L=[]
A=[]
B=[]
for _ in range(n):
    x,l=map(int,input().split())
    X.append(x)
    L.append(l)
    A.append(x-l)
    B.append(x+l)
k = zip(L,X,A,B)
k = sorted(k, key=lambda x:(x[1], x[2]))
c=1
ans=[]
ans.append((k[0][2],k[0][3]))
def judge(x,L):
    for l in L:
        if x[1]>l[0] and x[0] <l[1]:
            return False
    else:
        return True
for i in range(1,n):
    x=(k[i][2],k[i][3])
    if judge(x,ans):
        ans.append(x)
        c+=1
print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())
flag_ = False
flag = False
A = sorted([[int(i) for i in input().split()] for _ in range(N)])
B = []
for i in A:
    X,L = i[0],i[1]
    if flag_:
        if not flag and prev_arm > X-L:
            flag = True
        elif flag and prev_arm > X-L:
            B.pop()
            flag = False
        if prev_arm < X-L:
            flag = False
        B.append((X,L))
        prev_arm = X+L
    else:
        B.append((X,L))
        prev_arm = X+L
        flag_ = True
count = 0
for i in range(len(B)-1):
    if B[i][0] + B[i][1] > B[i+1][0] - B[i+1][1]:
        count += 1
print(len(B)-count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
XLlist = [tuple(map(int, input().split())) for _ in range(N)]
XLlist.sort()
ans = 1
x, l = XLlist[0]
rl = x + l - 1
for x, l in XLlist[1:]:
    l -= 1
    ll = x - l
    if ll <= rl:
        rl = min(rl, x + l)
    else:
        ans += 1
        rl = x + l
    # print(ll, rl, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
num_list = [[int(item) for item in input().split()] for _ in range(N)]
num_list.sort(key=lambda x: x[0]) 
# print(num_list)

temp_max = num_list[0][0] + num_list[0][1]
cnt = 1

for x, l in num_list:
    if x - l >= temp_max:
        cnt += 1
        temp_max = x + l
        # print(x, l, cnt, temp_max)


print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = []
L = []
PASS = []
for i in range(N):
  line = input().split(' ')
  X.append(int(line[0]))
  L.append(int(line[1]))
for i in range(N-1):
  for j in range(i,N):
    if X[i] > X[j]:
      t1 = X[i]
      t2 = L[i]
      X[i] = X[j]
      L[i] = L[j]
      X[j] = t1
      L[j] = t2
print(X,L)
for i in range(N-1):
  if i in PASS:
    continue
  for j in range(i+1,N):
    if X[i]+L[i] > X[j]-L[j]:
      PASS.append(j)
print(len(X)-len(PASS))

Submission status: Wrong Answer

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

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

n = inn()
xl = []
for i in range(n):
    xx,ll = inm()
    xl.append((xx,ll))
xl.sort()
x = [z[0] for z in xl]
l = [z[1] for z in xl]

ok = [1]*n
for i in range(1,n-1):
    if ok[i-1]==1 and x[i-1]+l[i-1] > x[i]-l[i] and \
       x[i]+l[i] > x[i+1]-l[i+1]:
        ok[i] = 0

for i in range(1,n):
    if x[i-1]+l[i-1] > x[i]-l[i] and ok[i-1]==1 and ok[i]==1:
        ok[i] = 0

print(sum(ok))

Submission status: Wrong Answer

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

robos.sort(key= lambda x:x[1])
# print(robos)
edge = -10000000000000
out = 0
for i in range(n):
    if robos[i][0] > edge:
        out += 1
        edge = robos[i][1]
    else:
        continue

robos = robos[::-1]

edge = 10000000000000
out2 = 0
for i in range(n):
    if robos[i][1] < edge:
        out2 += 1
        edge = robos[i][0]
    else:
        continue

# print(out2,out)

print(max(out2,out))

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(input())
    R = [None] * N
    for i in range(N):
        x, l = map(int, input().split())
        R[i] = (x + l, x - l)
    R.sort()
    
    right_most = R[0][0]
    save = 1
    for i in range(1, N):
        if R[i][1] >= right_most:
            save += 1
            right_most = R[i][1]

    print(save)


    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
N = int(input())
robots = {}
for _ in range(N):
    pos,armlen = map(int,input().split())
    robots[pos] = armlen

robots = sorted(robots.items(),key=lambda x:x[0])
range_min = robots[0][0] + robots[0][1]
ans = 1
for robot in robots[1:]:
    pos,armlen = robot
    if 0 <= (pos-armlen) <= range_min:
        ans += 1
        range_min = pos+armlen

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
b = []
for i in range(n):
  x,l = map(int,input().split())
  a.append(x-l)
  b.append(x+l)
  for j in range(len(a)):
    if a[j]<x-l<b[j] or a[j]<x+l<b[j]:
      a.pop()
      b.pop()
      break
print(len(a))

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-1, x-l+1))
    robo = sorted(robo, key = lambda x:x[0])

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

    print(ans)




    return 0

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

x.sort()
ans = n
i = 0
while(i < len(x) - 1):
    a = x[i][0] + x[i][1]
    b = x[i + 1][0] - x[i][1]
    if a > b:
        del x[i + 1]
        ans -= 1
    i += 1

print(ans)

Submission status: Wrong Answer

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


def solve(N: int, X: "List[int]", L: "List[int]"):
    xl = [[X[i], L[i]] for i in range(N)]
    xl = sorted(xl, key=lambda x:x[0])
    for i in range(1, N-1):
        t = i-1
        if xl[t][0] == -1:
            while(xl[t][0] != -1 and t > 0):
                t -= 1

        if xl[t][0]+xl[t][1] > xl[i][0]-xl[i][1] or xl[i][0]+xl[i][1] > xl[i+1][0]-xl[i+1][1]:
            xl[i][0] = -1

    if xl[0][0]+xl[0][1] > xl[N-1][0]-xl[N-1][1]:
        xl[N-1][0] = -1

    y = [xl[i][0] for i in range(len(xl)) if xl[i][0] != -1]
    # print(y)
    print(len(y))

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int()] * (N)  # type: "List[int]"
    L = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        X[i] = int(next(tokens))
        L[i] = int(next(tokens))
    solve(N, X, L)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())

sys.setrecursionlimit(10 ** 9)


def main():
    N = INT()
    l = []
    for _ in range(N):
        X, L = MAP()
        l.append([X-L, X+L])

    q = deque(sorted(l, key=lambda x: (x[0], x[1])))

    cnt = N
    xm, xl = q.popleft()
    for i in range(N-1):
        nm, nl = q.popleft()
        if nm < xl:
            cnt -= 1
        else:
            xm = nm
            xl = nl

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [[0,0] for _ in range(n)]
#print(a)
for i in range(n):
    a[i][0],a[i][1]=map(int,input().split())
a.sort()
for i in range(n):
    a[i][0],a[i][1]=(a[i][0]-a[i][1]),(a[i][0]+a[i][1])

now = 0
for i in range(n-1):
    if a[now][1]>a[now+1][0]:
        a.pop(now+1)
    else:
        now+=1
print(len(a))

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()
dp = {(-2 * 10 ** 9,0)}
for aa,bb in lis:
    now = set()
    for nowa,ans in dp:
        if nowa <= aa:
            now.add((bb,ans+1))
    dp = now
an = 0
for aaa,ans in dp:
    an = max(an,ans)
print(an)

Submission status: Wrong Answer

Solution code:

n = int(input())


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

count = 2
right = l[0][0]+l[0][1]
left = l[-1][0]-l[-1][1]
if right > left:
    print(1)
    exit()
for i in range(1,n):
    if l[i][0]-l[i][1] >= right:
        count += 1
        right = l[i][0]+l[i][1]
        
    if left >= l[-i-1][0]+l[-i-1][1]:
        count += 1
        left = l[-i-1][0]-l[-i-1][1]
        
    if right == left:
        print(count)
        exit()
    if right > left:
        count -= 1
        print(count)
        exit()
print(count)

Submission status: Wrong Answer

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


now = 1
before = 0
ans = n
while now < len(x):
    if x[before] + l[before] > x[now] - l[now]:
        if now == len(x) - 1:
            ans -= 1
            break
        if x[before] + l[before] > x[now + 1] - l[now + 1]:
            before = now
            ans -= 1
        else:
            ans -= 1
    else:
        before = now
    now += 1
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from bisect import bisect_left
N = int(input())
cnt = 0
T = []
for i in range(N):
    x, l = map(int, input().split())
    T.append([x, l])

T.sort(key=lambda x: x[0])
X, L = [], []
LL = []
for i in range(N):
    x, l = T[i]
    X.append(x)
    L.append(l)
    LL.append(x - l)
idx = 0
while idx < N - 1:
    x, l = X[idx], L[idx]
    n_idx = bisect_left(LL, x + l)
    if n_idx - idx > 1:
        cnt += 1
    idx += 1
print(N - cnt)

Submission status: Wrong Answer

Solution code:
import sys


def main():
    xl = []
    m = []
    cnt = 0
    num = 0
    n = int(input())
    for i in range(n):
        tmp = input().split(" ")
        xl.append([int(tmp[0]), int(tmp[1])])
    xl.sort()
    for i in range(n):
        m.append([xl[i][0] - xl[i][1], xl[i][0] + xl[i][1]])
    while num < n - 1:
        if m[num][1] > m[num + 1][0]:
            cnt += 1
            num += 1
        num += 1
    print(n-cnt)


if __name__ == '__main__':
    input = sys.stdin.readline
    main()

Submission status: Wrong Answer

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

ans = N
i = 1
l = i-1
while i < N:
    x1, l1 = r[l]
    x2, l2 = r[i]
    l = i
    if (x1+l1) > (x2-l2):
        i += 1
        ans -= 1
    i += 1
print(ans)