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())
s = [list(map(int, input().split())) for _ in [0] * n]

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

c = 0
i = 0
for i in range(10):
    while (i != len(s)-1 and i < len(s)):
        if s[i][1] >= abs(s[i][0] - s[i+1][0]):
            c += 1
            s.pop(i)
        i += 1


print(n-c)

Submission status: Wrong Answer

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

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

cntl = n
l = 0
r = 1
for i in range(10 ** 9):
    if x[l][0] + x[l][1] > x[r][0] - x[r][1]:
        cntl -= 1
        r += 1
    else:
        l = r
        r = l + 1
    if r > n - 1:
        break

cntr = n
l = 0
r = 1
x = x[::-1]
for i in range(10 ** 9):
    if x[l][0] - x[l][1] < x[r][0] + x[r][1]:
        cntr -= 1
        r += 1
    else:
        l = r
        r = l + 1
    if r > n - 1:
        break

print(max(cntr, cntl))

Submission status: Wrong Answer

Solution code:
import bisect

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


XL = sorted(XL)
MM.sort(key=lambda x: x[0])
MM.sort(key=lambda x: x[1])
migi = []
for i in range(N):
    migi.append(MM[i][1])
    
dp = [0]*(N+1)
dp[0] = 1
#print(MM)
for i in range(1,N):
    k = bisect.bisect_right(migi,MM[i][0]) - 1
    #print(k)
    if k >= 0:
        dp[i] = dp[k] + 1

ans = max(dp)
#print(dp)
print(ans)

Submission status: Wrong Answer

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

prv_idx = 0
idx = 1
removed_num = 0
while idx <= N-1:
    if ranges[idx][0] <= ranges[prv_idx][1]:
        removed_num += 1
        idx += 2
    else:
        idx += 1
        prv_idx += 1
    if N - 1 < idx:
        break
print(N - removed_num)

Submission status: Wrong Answer

Solution code:
import numpy as np

stdin = np.fromstring(open(0).read(), np.int64, sep=' ')
N = stdin[0]
XL = stdin[1:].reshape(-1, 2).T
x = XL[0]
l = XL[1]
arg = np.argsort(x)
x = x[arg]
l = l[arg]

xr = x + l
xl = x - l

count = 0
i = 0
while i < N - 1:
    for j in range(i + 1, N):
        if xr[i] > xl[j]:
            count += 1
        else:
            i = j
    else:
        break
print(N - count)

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 B[i]!=[10**9,0]:
    if B[i][1]>B[i+1][0] or B[i][0]<B[i-1][1]:
        ans +=1
        del B[i]
        continue
    i +=1
print(n-ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [[0,0] for _ in range(n)]

for i in range(n):
    a[i][0],a[i][1]=map(int,input().split())
a.sort()
cnt=0
now=0
temp=1
for i in range(n-1):
    if  a[now+temp][0]-a[now+temp][1]<a[now][0]+a[now][1]:
        cnt+=1
        temp+=1
    else:
        now+=temp
        temp=1

print(n-cnt)

Submission status: Wrong Answer

Solution code:
def solve():
    n = int(input())
    XL = sorted(list(map(int, input().split())) for _ in range(n))
    ans = n
    last = XL[0][0] + XL[0][1] - 1
    for x, l in XL[1:]:
        if last >= x - l + 1:
            ans -= 1
        else:
            last = x + l - 1
    print(ans)
solve()

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
l=sorted(l)
count=0
for i in range(n-1):
    l_range=l[i][1]+l[i+1][1]
    x_range=l[i+1][0]-l[i][0]
    if i!=n-2:
        if l[i][0]+l[i][1]>l[i+2][0]-l[i+2][1]:
            count+=1
            continue
    if l_range>x_range:
        count+=1
        l[i+1]=l[i]

print(n-count)

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=0
cnt=-(10**9)
li=[]
for i in range(n):
    X,L=map(int,input().split())
    li.append([X,L])
li=sorted(li,key=lambda x:x[0])
for i in range(n):
    if cnt>li[i][0]-li[i][1]:
        ans+=1
    else:
        cnt=li[i][0]+li[i][1]
print(n-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])

right = -10**9
removed = 0
for x, l in XL:
    if x-l < right:
        removed += 1
    else:
        right = x+l
print(N-removed)

Submission status: Wrong Answer

Solution code:
import sys

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

if(N==1):
  print("1")
  sys.exit()

rightX=robotList[0][0]+robotList[0][1]
leftX=0
count=0


for i in range(N-1):
  leftX=robotList[i+1][0]-robotList[i+1][1]
  if(rightX<=leftX):#共通範囲を持たない
    rightX=robotList[i+1][0]+robotList[i+1][1]
  else:#共通範囲を持つ
    count+=1
    
print(N-count)

Submission status: Wrong Answer

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

XL.sort()

result = 1
x, l = XL[0]
r = x + l
for i in range(1, N):
    x, l = XL[i]
    if r <= x - l:
        result += 1
        r = x + l
print(result)

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

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][0]+XL[i][1]
print(N-cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

XL = []
for i in range(N):
    tmp = list(map(int, input().split()))
    XL.append(tmp)
    
XL = sorted(XL, key=lambda x:x[0])

i = 0
now = 0
count = 0
while i <= len(XL)-2:
    now_arm = XL[now][0] + XL[now][1]
    if now_arm > XL[i+1][0] - XL[i+1][1]:
        count += 1
        now = i
    else:
        now = i
    i += 1    


#print(XL)
print(len(XL) - count)

Submission status: Wrong Answer

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

N = 100000
n = int(input())

x_list = [0]*N
l = [0]*N
x_list = [0]*N

# x_list_test = [0]*N

x, l = map(int, input().split())
x_min = max(0, x-l)
x_max = min(N-1, x+l-1)
temp = [1] * (x_max - x_min)
x_list[x_min:x_max] = temp
# print(x_list[:10])

ans = n
for i in range(n-1):
    x, l = map(int, input().split())
    x_min = max(0, x-l)
    x_max = min(N-1, x+l-1)
    
    # t = [1] * (x_max - x_min)
    # x_list_test[x_min:x_max] = t
    # print(x_list_test[:10])

    if 1 in x_list[x_min:x_max]:
        ans -= 1
    else:
        # temp = [1] * (x_max - x_min)
        x_list[x_min:x_max] = [1] * (x_max - x_min)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [list(map(int, input().split())) for _ in [0] * n]

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

c = 0
i = 0
while (i != len(s)-1 and i < len(s)):
    if s[i][1] >= abs(s[i][0] - s[i+1][0]):
        c += 1
        s.pop(i)
    i += 1


print(n-c)

Submission status: Wrong Answer

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


def solve(N: int, X: "List[int]", L: "List[int]"):
    d = {}
    for i in range(N):
        d[X[i]]=L[i]

    d=sorted(d.items())


    toru1=0
    maeR=d[0][0]+d[0][1]
    for i in range(1,N):
        tsugiL=d[i][0]-d[i][1]
        if maeR>tsugiL:
            toru1+=1
        else:
            maeR=d[i][0]+d[i][1]

    toru2=0
    maeL=d[N-1][0]-d[N-1][1]
    for i in reversed(range(N-1)):
        tsugiR=d[i][0]+d[i][1]
        if maeL<tsugiR:
            toru2+=1
        else:
            maeL=d[i][0]-d[i][1]

    print(N-min(toru1,toru2))
    
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int()] * (N)  # type: "List[int]"
    L = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        X[i] = int(next(tokens))
        L[i] = int(next(tokens))
    solve(N, X, L)

if __name__ == '__main__':
    main()

Submission status: 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)

R = [[X[n] - L[n], X[n] + L[n]] for n in range(N)]

R = sorted(R)
#print(R)

from bisect import bisect_right

rr = []

for r in R:
    rr += r
    

#print(rr)
s = []
through = False
sub = 0
for r in rr:
    idx = bisect_right(s, r)
    if through:
        through = False
        sub += 1

    elif idx == len(s):
        s.append(r)
    
    else:
        through = True
#print(s)
print(N - sub)

Submission status: Wrong Answer

Solution code:
N = int(input())
row = []
for n in range(N):
  x, l = [int(i) for i in input().split()]
  row.append((x,l))
orders = sorted(row, key=lambda x:x[0]) 

remain = N 
edge = -1000000000000000
Redge = 1000000000000000
for n in range(N):
  x0 = orders[n][0]
  l0 = orders[n][1]
  if n == N -1:
    re = Redge
  else:
    re = orders[n+1][0] + orders[n+1][1]
  if x0 - l0 < edge:
    remain -= 1
  elif x0 + l0 > re:
  	remain -= 1
  else:
    edge = x0 + l0

print(remain)

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

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())
xl = [list(map(int, input().split())) for _ in range(n)]

xx = []
count = 0

for x in xl:
    xx.append([x[0] - x[1], x[0] + x[1]])

if n != 2:
    for i in range(1, n-1):
        if xx[i][0] < xx[i-1][1] and xx[i][1] > xx[i+1][0]:
            count += 1
    print(n-count)
else:
    if xx[1][0] < xx[0][1]:
        print(1)
    else:
        print(2)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy
from pprint import pprint

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N = int(input())
    robots = []
    for _ in range(N):
        x,l = map(int, input().split())
        item = (x-l+1,x+l-1)
        robots.append(item)
    robots = sorted(robots, key=lambda x: x[1])
    #pprint(robots)

    candidates = []
    
    for i in range(N-1):
        a = robots[i]
        b = robots[i+1]
        if a[1] >= b[0]:
            candidates.append((i,i+1))
    #pprint(candidates)

    c = 0
    for i in range(len(candidates)-1):
        a = candidates[i]
        b = candidates[i+1]
        if a[1] == b[0]:
            c += 1
    ans = len(candidates)-c
    ans = N - ans

    print(ans)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
XL = []
for i in range(n):
  XL.append(list(map(int, input().split())))
XL.sort()
r = 0
cnt = 0
for i in range(n):
  xl = XL[i]
  tmp = xl[0]+xl[1]
  if xl[0]> r:
    r = tmp
    cnt += 1
    
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 j in PASS:
      continue
    if X[i]+L[i] > X[j]-L[j]:
      PASS.append(j)
print(PASS)
print(len(X)-len(PASS))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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

Submission status: 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=float("inf")
cnt=0
for i in range(n):
    a=ab[i][0]
    b=ab[i][1]
    if b<=A:
        cnt+=1
        A=a
print(cnt)

Submission status: Wrong Answer

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

remove = 0
reach = 0

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

    if i == 0:
        reach = right
        continue

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

print(N - remove)

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:]):
    if before_value[1] >= after_value[0]:
        minus_count += 1

print(len(sort_robot_list) - minus_count)

Submission status: Wrong Answer

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

ranges.sort()

if (len(ranges) == 1):
    print(1)

elif (len(ranges) == 2):
    if (ranges[1][0] < ranges[0][1]):
        print(1)
    else:
        print(2)

else:
    corr = [0 for i in range(n+1)]
    temp = []

    while True:
        
        l = len(ranges)

        for i in range(l-2):
            if (ranges[i+1][0] < ranges[i][1]):
                if (ranges[i+2][0] < ranges[i+1][1]):
                    corr[i+1] = 1
                    ranges[i+1] = ranges[i]
                else:
                    corr[i] = 1
                    if (i != 0):
                        ranges[i] = ranges[i-1]

        if (set(corr)) == {0}:
            break
        
        for i in range(l):
            if (corr[i] == 1):
                pass
            else:
                temp.append(ranges[i])

        ranges = list(temp)
        temp = []
        corr = [0 for i in range(len(ranges))]

    print(len(corr))

Submission status: Wrong Answer

Solution code:
n = int(input())


effect = 0
count = 0
armsize = 0

d = {}
for i in range(1, n+1):
  x, l = map(int, input().split())
  d[x] = l
  
d = {p[0]:p[1] for p in sorted(d.items())}

for x, l in d.items():

  if x - l < armsize:
    effect += 1
    if effect > 1:
      count += 1
      effect = 0
    else:
      pass
  else:
    effect = 0
    
  armsize = x + l

print(n - count)

Submission status: Wrong Answer

Solution code:
import bisect

n = int(input())
machine = []
machine_left = []
machine_right = []
for i in range(n):
    x, l = [ int(v) for v in input().split() ]
    machine.append((x, l))
machine.sort()

for x, l in machine:
    machine_left.append(x-l)
    machine_right.append(x+l)

dp_list = [1] * n
for i in range(n):
    a = bisect.bisect_left(machine_left, machine_right[i])
    if a < n:
        dp_list[a] = max(dp_list[a], dp_list[i] + 1)

print(max(dp_list))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
xl = [list(map(int, input().split())) for _ in range(n)]
lr = sorted([[xl[i][0]-xl[i][1],xl[i][0]+xl[i][1]] for i in range(n)])

cnt = 1
cl = lr[0][0]
cr = lr[0][1]
for l,r in lr[1:]:
    if cr<=l:
        cr = r
        cl = l
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())

L=[]
for i in range(n):
    x,l=map(int,input().split())
    L.append([x,l])
L.sort(key=lambda x:x[0])
ans=1
before=L[0][0]+L[0][1]
for i in range(1,n):
    if before<=L[i][0]-L[i][1]:
        before=max(before,L[i][0]+L[i][1])
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())

    xls = []

    ans = N
    for i in range(N):
        xl = [int(k) for k in input().split(" ")]
        if i == 0:
            xls.append(xl)
        else:
            xl_before = xls[-1]
            x_before = xl_before[0]
            l_before = xl_before[1]
            x = xl[0]
            l = xl[1]
            if abs(x - x_before) < l + l_before:
                ans -= 1
            else:
                xls.append(xl)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
xl =[[int(x) for x in input().split()]for _ in range(N)]
xl = sorted(xl,key = lambda x:x[1])
xl = sorted(xl,key = lambda x:x[0])
minx=0
maxx=0
cnt=0
for i in range(N):
  mina=max(xl[i][0]-xl[i][1],0)
  maxa = xl[i][0]+xl[i][1]
  if maxx<=mina:
    maxx=maxa
  else:
    cnt+=1
print(N-cnt)

Submission status: Wrong Answer

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

count1 = N
temp = X[0][0] + X[0][1]
for i in range(N - 1):
    if X[i + 1][0] - X[i + 1][1] < temp:
        count1 -= 1
    else:
        temp = X[i + 1][0] + X[i + 1][1]

count2 = N
temp = X[N - 1][0] - X[N - 1][1]
for i in range(N - 1):
    if X[N - 2 - i][0] + X[N - 2 - i][1] > temp:
        count2 -= 1
    else:
        temp = X[N - 2 - i][0] - X[N - 2 - i][1]

print(max(count1, count2))

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:
n = int(input())
robots = []
for _ in range(n):
    x, l = map(int, input().split())
    robots.append((x, l))
robots.sort()

ok = [True for _ in range(n)]
p = 0
q = 1
while p < n and q < n:
    if p == q:
        q += 1
        continue
    
    x1, l1 = robots[p]
    x2, l2 = robots[q]
    if x1 + l1 <= x2 - l2:
        p = q
        q = p + 1
    else:
        ok[q] = False
        q += 1

c = 0
for v in ok:
    if v:
        c += 1
print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())
alllist = []
remain = 0
for i in range(N):
    X, L = map(int,input().split())
    numberlist = []
    for j in range(X-L,X+L):
        if j in alllist:
            remainad = 0
            numberlist = []
            break
        
        else:
            remainad = 1
            numberlist.append(j)
    remain += remainad
    for p in range(len(numberlist)):
        alllist.append(p)
print(remain)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = [0]*n
l = [0]*n
li = []
for i in range(n):
  x[i], l[i] = list(map(int, input().split()))
  li.append([x[i], l[i]])
li.sort()
for i in range(n):
  x[i] = li[i][0]
  l[i] = li[i][1]
  
count = 0
if n == 2:
  if (x[0] + l[0]) <= (x[1] - l[1]):
    print(1)
  else:
    print(n)
else:
  for i in range(n):
    if i == 0 or i == n-1:
      continue
    else:
      top = (x[i] + l[i]) <= (x[i+1] - l[i+1])  
      if top == False:
        count += 1

  print(n - count)

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][0]+XL[i][1]
print(N-cnt)

Submission status: Wrong Answer

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


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

    for i in range(n):
        xi, li = map(int, input().split())
        y.append((xi - li + 1, xi + li - 1))

    count = 1
    sorted_y = sorted(y, key=lambda x: x[1])
    end_point = sorted_y[0][1]

    for left, right in sorted_y[1:]:
        if left > end_point:
            end_point = right
            count += 1

    print(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
li=[]
for i in range(0,n):
    flag=True
    x,l=map(int, input().split())
    mi=x-l
    ma=x+l
    for j in li:
        if j[0] < mi < j[1] or j[0] < ma <j[1]:
            flag=False
            break
    if flag:
        li.append([mi,ma])
print(len(li))

Submission status: Wrong Answer

Solution code:
import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
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 MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
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()
    s = []
    for i in range(N):
        x,l=MI()
        s.append([x,l])
    s.sort(key=lambda x:x[0])
    p=[]    
    for i in range(N):
        x,l=s[i]
        p.append([x-l,x+l])
    # print(p)
    prev=p[0]
    c=0
    for i in range(1,N):
        # print(p[i][0],prev[1])
        if p[i][0]<prev[1]:
            c+=1
        else:
            prev=p[i]
    prev=p[-1]
    c1=0
    for i in range(N-2,-1,-1):
        # print(p[i][0],prev[1])
        if p[i][1]>prev[0]:
            c1+=1
        else:
            prev=p[i]
    print(max(N-c,N-c1))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
xl=[list(map(int,input().split())) for _ in range(n)]
xl.sort(key=lambda x: x[0])
cnt=0
nx,nl=xl[0]
for i in range(1,n):
  x,l=xl[i]
  if nx+nl<=x-l:
    nx=x
    nl=l
  else:
    cnt+=1
print(n-cnt)

Submission status: Wrong Answer

Solution code:
import sys

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

if(N==1):
  print("1")
  sys.exit()

rightX=robotList[0][0]+robotList[0][1]
leftX=0
count=0


for i in range(N-1):
  leftX=robotList[i+1][0]-robotList[i+1][1]
  if(rightX<=leftX):#共通範囲を持たない
    rightX=robotList[i][0]+robotList[i][1]
  else:#共通範囲を持つ
    count+=1
    
print(N-count)

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][1]
    if a > b:
        del x[i + 1]
        ans -= 1
    else:
        i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted([list(map(int, input().split())) for _ in range(n)])
r = a[0][0]+a[0][1]-1
l = 0
for j in range(1,n):
    i = a[j]
    l = i[0]-i[1]+1
    #print(l,r)
    if r < l:
        r = i[0]+i[1]-1
    else:
        n -= 1
print(n)

Submission status: Wrong Answer

Solution code:
N = int(input())
ls = []
ls_append = ls.append

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

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

del_flag = False
cnt = 0

for i in range(1, len(ls)):
    if del_flag:
        del_flag = False
        continue
    x0 = ls[i - 1][0]
    l0 = ls[i - 1][1]
    x1 = ls[i][0]
    l1 = ls[i][1]
    range_0 = x0 + l0
    range_1 = x1 - l1
    if range_0 > range_1:
        cnt += 1
        del_flag = True
        
print(N - cnt)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    N = int(input())
    R = []
    for _ in range(N):
        X, L = map(int, input().split())
        R.append([X, L])
    R.sort()

    res = 1
    tmp = R[0][0] + R[0][1]
    for i in range(1, N):
        ntmp = R[i][0] - R[i][1]
        if tmp <= ntmp:
            res += 1
            tmp = ntmp

    print(res)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

robo_list.sort()
#print(robo_list)

xmax = 0
counter = 0
for i in range(N):
    if(i==0):
        robo = robo_list[i]
        xmax = robo[0]+robo[1]
        counter += 1
    else:
        robo = robo_list[i]
        if(robo[0]-robo[1] >= xmax):
            xmax = robo[0]+robo[1]
            counter += 1
        else:
            pass
            
    
print(counter)

Submission status: Wrong Answer

Solution code:
import sys
from pprint import pprint

def solve(n, x, l):
    r = []
    for i in range(n):
        r.append((x[i], l[i]))

    x_pre = -1
    l_pre = 0
    remove = 0
    for x_i, l_i in sorted(r):
        if x_pre == -1:
            x_pre = x_i
            l_pre = l_i
            continue
        # print("pre", x_pre, l_pre)
        # print(x_i, l_i)
        if x_i - l_i < x_pre + l_pre:
            # 先まで届かない方を残す
            if x_pre + l_pre > x_i + l_i:
                x_pre = x_i
                l_pre = x_i
            remove += 1
    print(n - remove)


if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    x = [0] * n
    l = [0] * n
    for i in range(n):
        x[i], l[i] = map(int, sys.stdin.readline().strip().split(" "))
    solve(n, x, l)

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

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


# print(xl)
ans = 0
p = len(xl) - 1

i = 0
while(i < p):
    if (xl[i][1] > xl[i + 1][0]):
        ans += 1
        xl.pop(i + 1)
        p -= 1
    else:
        i += 1
# print(xl)

print(n-ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
l=sorted(l)
count=0
for i in range(n-1):
    l_range=l[i][1]+l[i+1][1]
    x_range=l[i+1][0]-l[i][0]
    if i!=n-2:
        if l[i][0]+l[i][1]>l[i+2][0]-l[i+1][1]:
            count+=1
            continue
    if l_range>x_range:
        count+=1
        l[i+1]=l[i]

print(n-count)

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(0))
i = 1
while i != len(XL):
    if XL[i - 1][0] + XL[i - 1][1] > XL[i][0] - XL[i][1]:
        XL.pop(i)
    else:
        i += 1

print(len(XL))