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())
x = []
for i in range(n):
    tmpx, tmpl = map(int,input().split())
    x.append((tmpx,tmpl))
x = sorted(x)
#print(x)
ans = n

flag = 1
for i in range(n-1):
    if x[i][0]+x[i][1]>x[i+1][0] and flag != i-1:
        ans -= 1
        flag = i
print(ans)

Submission status: Wrong Answer

Solution code:
H = int(input())

_list = []

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

new_list = sorted(_list)

ans_list = [new_list[0]]
for i in new_list:
  arm_long = ans_list[-1][0] + ans_list[-1][1] -1
  arm_short = i[0] - i[1] +1
  if arm_long < arm_short:    
    ans_list.append(i)
  else:
    arm_long_new = i[0] + i[1] - 1
    if arm_long >= arm_long_new:
      ans_list[-1] = i

print(len(ans_list))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
r = []
for i in range(n):
    x, l = map(int, input().split())
    r.append((x - l + 1, x + l - 1))
r.sort()
am = [[] for _ in range(n)]
for i in range(n):
    for j in range(i + 1, n):
        if r[i][1] < r[j][0]:
            break
        am[i].append(j)
        am[j].append(i)
print(am)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, XL):
    ans = 0
    XL.sort(key=lambda x: x[0])
    XL.sort(key=lambda x: x[1])

    s = []
    for x, l in XL:
        lp, rp = x-l+1, x+l-1
        s.append((lp, rp))

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


    cand = []
    ans = 0
    for l, r in s:
        for ll, rr in cand:
            if rr >= l:
                break
        else:
            ans += len(cand)
            cand = [(l, r)]

    return ans + len(cand)

    # p.sort()
    # d = {}
    # for i, v in enumerate(p):
    #     d[v] = i

    # ans = 0
    # a = [0] * len(p)
    # for lp, rp in s:
    #     # print(lp, rp)
    #     l = d[lp]
    #     r = d[rp]
    #     print(l, r)
    #     for i in range(l, r+1):
    #         if a[i] != 0:
    #             break
    #     else:
    #         ans += 1
    #         for i in range(l, r+1):
    #             a[i] = 1
    # return ans


def main():
    N = read_int()
    XL = [read_int_n() for _ in range(N)]
    print(slv(N, XL))

    # N = 10**5
    # XL = [[random.randint(0, 10**9), random.randint(0, 10**9)] for _ in range(N)]
    # print(slv(N, XL))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
x=[]
for i in range(n):
    s,p = map(int,input().split())
    x.append([s,p])
a=sorted(x)
count=0
xmax = 0
xmin = 0
C = 1
for t in a:
    if count == 0:
        xmax = int(t[0])+int(t[1])
        xmin = int(t[0])-int(t[1])
    else:
        Xmax = int(t[0])+int(t[1])
        Xmin = int(t[0])-int(t[1])
        if xmax<=Xmin:
            C+=1
            xmax = Xmax
            xmin = Xmin
            
    count=1
print(C)

Submission status: Wrong Answer

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

for index, arm in enumerate(s):
  if index+1 == len(s):
    break
  if index >0:
    if arm[0]+arm[1]>s[index+1][0]-s[index+1][1] and arm[0]-arm[1] < s[index-1][0]+s[index-1][1]:
      s.remove(arm)

for index, arm in enumerate(s):
  if index+1 == len(s):
    break
  if arm[0]+arm[1] > s[index+1][0]-s[index+1][1]:
    s.remove(arm)
  
print(len(s))

Submission status: Wrong Answer

Solution code:
H = int(input())

_list = []

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

new_list = sorted(_list)

ans_list = [new_list[0]]
for i in new_list:
  arm_long = ans_list[-1][0] + ans_list[-1][1] -1
  arm_short = i[0] - i[1] +1
  if arm_long < arm_short:    
    ans_list.append(i)
  else:
    arm_long_new = i[0] + i[1] - 1
    if arm_long > arm_long_new:
      ans_list[-1] = i
print(ans_list)

print(len(ans_list))

Submission status: Wrong Answer

Solution code:
n = int(input())
xl = []
for i in range(n):
    x1, l1 = map(int, input().split())
    xl.append([x1, x1 - l1, x1 + l1])
xl.sort()
ans = n
import copy
xl2 = copy.deepcopy(xl)
xl2 = xl2[::-1]
for i in range(1, n - 1):
    # print(xl, i)
    if xl[i - 1][2] > xl[i][1] and xl[i][2] > xl[i + 1][1]:
        xl[i] = copy.copy(xl[i - 1])
        ans -= 1
    elif xl[i - 1][2] > xl[i][1]:
        xl[i] = copy.copy(xl[i - 1])
        ans -= 1

ans1 = ans
ans = n
xl == xl2
for i in range(1, n - 1):
    # print(xl, i)
    if xl[i - 1][2] > xl[i][1] and xl[i][2] > xl[i + 1][1]:
        xl[i] = copy.copy(xl[i - 1])
        ans -= 1
    elif xl[i - 1][2] > xl[i][1]:
        xl[i] = copy.copy(xl[i - 1])
        ans -= 1

if n == 2:
    if xl[i - 1][2] > xl[i][1]:
        ans -= 1

print(min(ans1, ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
x_l = {}
for i in range(n):
    x,l = map(int, input().split())
    x_l[l] = x
if n ==1 :
    print(1)
    exit()
del_num = 0
sort_key = sorted(x_l.keys())
min_max = [max(0, x_l[sort_key[0]] - sort_key[0]), min(10**9, x_l[sort_key[0]] + sort_key[0])]
for i in sort_key[1:]:
    if min_max[1] >  (x_l[i] - i):
        del_num+=1
        min_max[1] = min(min_max[1], x_l[i] + i) 
    else:
        min_max[1] = (x_l[i] - i)
print(n-del_num)

Submission status: Wrong Answer

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

print(N - tikan)

Submission status: Wrong Answer

Solution code:
num = int(input())
j = 0
counter = 0

input_l = []

for i in range(num):
    a = input().split(" ")
    input_l.append(a)

while True:
    temp = input_l
    for i in range(len(input_l) - 1):
        if int(input_l[i][0]) > int(input_l[i+1][0]):
            x = input_l[i]
            input_l[i] = input_l[i+1]
            input_l[i+1] = x
    if temp == input_l:
        break


while True:
    if j == len(input_l) - 1:
        break
    if (int(input_l[j][0]) + int(input_l[j][-1])) - (int(input_l[j+1][0]) + int(input_l[j+1][-1])) > 0:
        if (int(input_l[j][0]) + int(input_l[j][-1])) - (int(input_l[j+1][0]) - int(input_l[j+1][-1])) > 0:
            del input_l[j]
            counter += 1
        else:
            counter += 1
            del input_l[j+1]
    else:
        j += 1

print(num - counter)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = []
L = []
XL = []
for i in range(N):
  temp = list(map(int, input().split()))
  X.append(temp[0])
  L.append(temp[1])
  XL.append(temp[0]+temp[1])
  
num = 0
area = []
for i in range(N):
  flag = 0
  left  = X[i]-L[i]+1
  right = X[i]+L[i]-1
  if(left<0):
    left = 0
  for j in range(len(area)):
    if( (left >= area[j][0] and left <= area[j][1]) or (right >= area[j][0] and right <= area[j][1]) ):
      num += 1
      flag = 1
      break
  if(flag == 0):
    temp = [left, right]
    area.append(temp)
  
    
print(N-num)

Submission status: Wrong Answer

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

for index, arm in enumerate(s):
  if index+1 == len(s):
    break
  if index >0:
    if arm[0]+arm[1]>s[index+1][0]-s[index+1][1] and arm[0]-arm[1] < s[index-1][0]+s[index+1][1]:
      s.remove(arm)

for index, arm in enumerate(s):
  if index+1 == len(s):
    break
  if arm[0]+arm[1] > s[index+1][0]-s[index+1][1]:
    s.remove(arm)
  
print(len(s))

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = [list(map(int,input().split())) for i in range(N)]
arr = sorted(arr, key=lambda x:x[0])
F = [True]*N
P = [0]*N
for i in range(N):
  P[i] = [arr[i][0]-arr[i][1], arr[i][0]+arr[i][1]]
ind = 0
for i in range(1,N):
    if P[i][0] < P[ind][1]:
      if P[ind][1] > P[i][1]:
        F[ind] = False
        ind += 1
      else:
        F[i] = False
    else:
      ind = i
print(F.count(True))

Submission status: Wrong Answer

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

N = int(input())
X,L = [],[]

for _ in range(N):
    x,l = input().split()
    X.append(int(x))
    L.append(int(l))

i = 0
while i < len(X):
    
    if i>0 and X[i]-L[i] <= X[i-1]-L[i-1]:
        X.pop(i-1)
        L.pop(i-1)
    elif i<len(X)-1 and X[i]+L[i] >= X[i+1]+L[i+1]:
        X.pop(i+1)
        L.pop(i+1)
    else:
        i+=1

print(len(X))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = []
for i in range(n):
    tmpx, tmpl = map(int,input().split())
    x.append((tmpx,tmpl))
x = sorted(x)
#print(x)
ans = n

flag = 1
for i in range(n-1):
    if x[i][0]+x[i][1]>x[i+1][0] and flag != i:
        ans -= 1
        flag = i
print(ans)

Submission status: Wrong Answer

Solution code:
H = int(input())

_list = []

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

new_list = sorted(_list)

ans_list = [new_list[0]]
for i in new_list:
  arm_long = ans_list[-1][0] + ans_list[-1][1] -1
  arm_short = i[0] - i[1] +1
  if arm_long < arm_short:    
    ans_list.append(i)
  else:
    arm_long_new = i[0] + i[1] - 1
    if arm_long >= arm_long_new:
      ans_list[-1] = i
print(ans_list)

print(len(ans_list))

Submission status: Wrong Answer

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

#print(xl)
xl.sort()
#print(xl)
#exit()

#kazu = 2*10**9

plus = []
minus = []

for i in range(n):
    plus.append(xl[i][0]-xl[i][1]+1)
    minus.append(xl[i][0]+xl[i][1]-1)

#plus.sort()
#minus.sort()

num = 0
ima = n
mi_num = 0

for i in range(n-1):
    if minus[i+mi_num]  > plus[i+1]:
        ima -= 1
        mi_num -= 1
        
print(ima)

Submission status: Wrong Answer

Solution code:
n = int(input())
xl = []
for i in range(n):
    x1, l1 = map(int, input().split())
    xl.append([x1, x1 - l1, x1 + l1])
xl.sort()
ans = n
import copy
for i in range(1, n - 1):
    # print(xl, i)
    if xl[i - 1][2] > xl[i][1] and xl[i][2] > xl[i + 1][1]:
        xl[i] = copy.copy(xl[i - 1])
        ans -= 1
    elif xl[i - 1][2] > xl[i][1]:
        xl[i] = copy.copy(xl[i - 1])
        ans -= 1

ans1 = ans
ans = n
xl == xl[::-1]
for i in range(1, n - 1):
    # print(xl, i)
    if xl[i - 1][2] > xl[i][1] and xl[i][2] > xl[i + 1][1]:
        xl[i] = copy.copy(xl[i - 1])
        ans -= 1
    elif xl[i - 1][2] > xl[i][1]:
        xl[i] = copy.copy(xl[i - 1])
        ans -= 1

if n == 2:
    if xl[i - 1][2] > xl[i][1]:
        ans -= 1

print(min(ans1, ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# N個のロボット
N = int(input())

# 1個前
rem = 0
bx = 0
bl = 0
for i in range(N):
    x,l = map(int, input().split())
    
    #print(x,l, bx,bl)
    
    # 1個前と重複確認
    if i != 0:
        
        # 1個前と比べて、範囲が重複してなければOK
        #print(bx - bl , bx+bl, x-l ,x+l)
        if (bx - bl <= bx+bl < x-l <= x+l):
            # 1個前を更新
            bx = x
            bl = l
        else:
            #print("rem")
            rem +=1
            # 1個前は変えないで次へ
            continue

    else:
        # 1個前を更新
        bx = x
        bl = l
    

print(N-rem)

Submission status: Wrong Answer

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

removal_count = 0
for index, arm in enumerate(s):
  if index+1 == len(s):
    break
  if index >0:
    if arm[0]+arm[1]>s[index+1][0]-s[index+1][1] and arm[0]-arm[1] < s[index-1][0]+s[index+1][1]:
      s.remove(arm)
print(s)

for index, arm in enumerate(s):
  if index+1 == len(s):
    break
  if arm[0]+arm[1] > s[index+1][0]-s[index+1][1]:
    s.remove(arm)
  
print(len(s))

Submission status: Wrong Answer

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

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

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

from bisect import bisect_right

rr = []

s = []
sub = 0
for r in R:
    sIdx = bisect_right(s, r[0][0])
    eIdx = bisect_right(s, r[0][1])

    if sIdx == len(s) and eIdx == len(s):
        s.append(r[0][0])
        s.append(r[0][1])

    else:
        sub += 1
#print(s)
print(N - sub)

Submission status: Wrong Answer

Solution code:
N = int(input())
xs = []
r = 1
for i in range(N):
    x, l = map(int, input().split())
    a,b = x-l, x+l
    xs.append((a,b))
xs.sort()
for i, (a, b) in enumerate(xs):
    if i == 0:
        ba, bb= a, b
        continue
    if a<bb:
        continue
    else:
         ba, bb = a, b
         r += 1
print(r)

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = [list(map(int,input().split())) for i in range(N)]
arr = sorted(arr, key=lambda x:x[0])
F = [True]*N
P = [0]*N
for i in range(N):
  P[i] = [arr[i][0]-arr[i][1], arr[i][0]+arr[i][1]]
ind = 0
for i in range(1, N):
  if i == 1:
    if P[0][1] > P[1][0]:
      if P[0][1] <= P[1][1]:
        F[1] = False
      else:
        F[0] = False
        ind += 1
  else:
    if P[i][0] < P[ind][1]:
      if P[ind][1] > P[i][1]:
        F[ind] = False
        ind += 1
      else:
        F[i] = False
    else:
      ind = i
print(F.count(True))

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect_left as bl
input = sys.stdin.readline
print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
xl = [[0, 0] for i in range(n)]
for i in range(n):
  xl[i] = list(map(int, input().split()))
xl.sort()
bef = xl[0]
c = 1
for i in range(1, n):
  if xl[i][0] - xl[i][1] < bef[0] + bef[1]:
    if xl[i][0] + xl[i][1] <= bef[0] + bef[1]:
      bef = xl[i]
  else:
    c += 1
print(c)

Submission status: Wrong Answer

Solution code:
n=int(input())
li=[None]*n
for i in range(0,n):
    flag=True
    x,l=map(int, input().split())
    li[i]=(x,l)
li=sorted(li)
for i in range(n):
    if li[i] == None:
        continue
    x,l = li[i]
    for j in range(i+1,n):
        x2,l2 = li[j]
        if x+l <= x2-l2:
            break
        li[j] = None
print(len(li) - li.count(None))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = []
for i in range(n):
    tmpx, tmpl = map(int,input().split())
    x.append((tmpx,tmpl))
x = sorted(x)
#print(x)
ans = n

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

Submission status: Wrong Answer

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

XL.sort()

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

result2 = 0
r = -(10 ** 9)
for i in range(1, N):
    x, l = XL[i]
    if r <= x - l:
        result2 += 1
        r = x + l

print(max(result1, result2))

Submission status: Wrong Answer

Solution code:
n=int(input())
x=[]
l=[]

result = n

buf=[0 for i in range(n)]

for i in range(n):
    xx,ll=map(int, input().split())
    x.append(xx)
    l.append(ll)

c=zip(x,l)
d=sorted(c)

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

print(result)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

N = int(input())

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

bound = []
for value in xl:
    bound.append([value[0] - value[1] + 1, value[0] + value[1] - 1, value[1]])

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

left = bound[0][0]
right = bound[0][1]
ans = 1
for i in range(1, N):
    new_left = bound[i][0]
    new_right = bound[i][1]
    if new_left > right:
        ans += 1
        left = new_left
        right = new_right   
    else:
        if new_right <= right:
            left = new_left
            right = new_right
print(ans)

Submission status: Wrong Answer

Solution code:
def solve():
    pass

def main():
    n = int(input())
    points = []
    for i in range(n):
        x,l = map(int,input().split())
        points.append((x-l,"start"))
        points.append((x+l,"end"))
    points.sort(key = lambda x:(x[0] + (0.5 if x[1] == "start" else 0)))
    before = "start"
    counter = 0
    #print(points)

    for p in points:
        if p[1] == "start":
            before = "start"


        if p[1] == "end":
            if before == "start":
                #print(p[0],"find top!")
                counter += 1
            before = "end"


    print(counter)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

P = [0] * 150

robot = []

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

    robot.append([X,L])

robot = sorted(robot)

p_max = robot[0][0] + robot[0][1]
cnt = 1

for i in range(1,N):
    if p_max <= robot[i][0] - robot[i][1]:
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

cnt = N

for i in range(N):
    X[i], L[i] = map(int, input().split())
    
index_sort = np.argsort(X)
X_sort = sorted(X)

L_sort = [0] * N

for i in range(N):
  L_sort[i] = L[ index_sort[i] ]

if(N >= 3):
  for i in range(1, N - 1):
    if( X_sort[i] - X_sort[i-1] < L_sort[i] or
        X_sort[i] - X_sort[i-1] < L_sort[i-1] ):
      X_sort[i]=X_sort[i-1]
      L_sort[i]=L_sort[i-1]
      cnt -= 1 
    elif( X_sort[i+1] - X_sort[i] < L_sort[i] or
          X_sort[i+1] - X_sort[i] < L_sort[i+1]):
      cnt -= 1 

  j = 1
  while( X_sort[j] == X_sort[j+1] ):
    j += 1
    if( j == N - 1):
      break

  j += 1
  if( X_sort[j] - X_sort[0] < L_sort[0] or
    X_sort[j] - X_sort[0] < L_sort[j]):
    if( X_sort[j] != X_sort[0] ):
      cnt -= 1
      
elif(N < 3 and N != 1):
  if( X_sort[1] - X_sort[0] < L_sort[0] or
    X_sort[1] - X_sort[0] < L_sort[1]):
      if( X_sort[1] != X_sort[0] ):
        cnt -= 1
        
else:
  i = 0
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
xl = []
for i in range(n):
    x1, l1 = map(int, input().split())
    xl.append([x1, x1 - l1, x1 + l1])
xl.sort()
ans = n
import copy
for i in range(1, n - 1):
    # print(xl, i)
    if xl[i - 1][2] > xl[i][1] and xl[i][2] > xl[i + 1][1]:
        xl[i] = copy.copy(xl[i - 1])
        ans -= 1
    elif xl[i - 1][2] > xl[i][1]:
        xl[i] = copy.copy(xl[i - 1])
        ans -= 1
if n == 2:
    if xl[i - 1][2] > xl[i][1]:
        ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N = inputInt()
	tmp = []
	for i in range(N):
		X,L = inputMap()
		LL = X-L
		RR = X+L
		tmp.append((LL,RR))

	tmp.sort()
	ddeell = []
	for i,val in enumerate(tmp):
		if i == len(tmp)-1:
			break
		LL, RR = val
		LL2, RR2 = tmp[i+1]

		if RR > RR2:
			ddeell.append((LL,RR))

	habu = len(ddeell)

	for val in ddeell:
		tmp.remove(val)

	kabu = 0
	tt = []
	for i,val in enumerate(tmp):
		if i == len(tmp)-1:
			break

		ima_L,ima_R = val
		tugi_L, tugi_R = tmp[i+1]

		if ima_R > tugi_L:
			kabu += 1

		tt.append(kabu)
		kabu = 0

	#print(tt)
	flg = False
	for i in tt:
		#print(i)
		if i == 1 and flg == False:
			habu += 1
			flg = True
		elif i == 1 and flg == True:
			flg = False

	print(N-habu)


if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

d.sort(key=lambda x:x[1],reverse=False)
#left.sort(key=lambda x:x[1],reverse=False)
#right.sort(key=lambda x:x[2],reverse=False)
#print(d)
p_r = 10**10 + 1
p_l = -1 * (10**10 + 1)
ans = 0
flag = True

for j in range(n):
    i,l,r = d.pop(0)
    if j == 0:
        p_l = l
        p_r = r
        ans += 1
    else:
        if l > p_r:
            p_l = l
            p_r = r
            ans += 1
        else:
            if r > p_r:
                pass
            else:
                p_l = l
                p_r = r

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
list = [list(map(int, input().split())) for i in range(n)]
ans = []
list.sort(key=lambda x: x[0])

list2 = []
for i in range(n):
    list2.append(list[i][0] - list[i][1])
    list2.append(list[i][0] + list[i][1])

for i in range(1,n-1):
    if list2[i] > list2[i+1] and not(list2[i] in ans):
            ans.append(list2[i+1])
    elif list2[i-2] > list2[i+1] and i != 1:
        ans.append(list2[i+1])
    i += 1
print(n - len(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
l = list()
for i in range(N):
  X, L = map(int, input().split())
  left = X - L
  right = X + L
  l.append([left, right])
l.sort()
cnt = 0
n = 0
t = 1
while t < N:
  if l[n][1] > l[t][0]:
    cnt += 1
  else:
    n = t
  t += 1
print(N - cnt)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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

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

for i in range(N -1):
    if X[i] > X[i+1]:
              tempX = X[i]
              X[i] = X[i+1]
              X[i+1] = tempX
              tempL = L[i]
              L[i] = L[i+1]
              L[i+1] = tempL

count = 0
leng1 = 0
leng2 = 0

for i in range(N-1):
    right1 = X[i] + L[i]
    left1 = X[i] - L[i]
    right2 = X[i+ 1] + L[i+ 1]
    left2 = X[i+ 1] - L[i+ 1]
    if right1 < left2 or left2 < 0:
           count = count + 1

print(N - count)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

N = int(input())
robots_attr = {}
robots = []
for _ in range(N):
    x, l = map(int, input().split(' '))
    robots.append(x)
    robots_attr[x] = {'len': l, 'eliminated': False}

robots = sorted(robots)
eliminated = 0

for i in range(N):
    if robots_attr[robots[i]]['eliminated']:
        continue
    if i != N-1:
        shift = 0
        while 1:
            if (i+1+shift <= N-1) and (robots[i] + robots_attr[robots[i]]['len'] - 1 >= robots[i+1+shift] - robots_attr[robots[i+1+shift]]['len'] + 1):
                robots_attr[robots[i]]['eliminated'] = True
                eliminated += 1
                shift += 1
            else:
                break
    else:
        shift = 0
        need_check = True
        while 1:
            if i-1-shift < 0:
                need_check = False
                break
            if robots_attr[robots[i-1-shift]]['eliminated']:
                shift += 1
            else:
                break
        if need_check and robots[i] - robots_attr[robots[i]]['len'] + 1 <= robots[i-1-shift] + robots_attr[robots[i-1-shift]]['len'] - 1:
                robots_attr[robots[i]]['eliminated'] = True
                eliminated += 1

print(N - eliminated)

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 = sorted(robots, key=lambda x: x[0])
rightest_point = robots[0][0] + robots[0][1] - 1
ans = 0
for i in range(1, len(robots)):
    if robots[i][0]-robots[i][1] + 1 < rightest_point:
        ans += 1
        continue
    else:
        rightest_point = robots[i][0]+robots[i][1] - 1
first = N-ans

# 後ろから
robots = sorted(robots, key=lambda x: x[0], reverse=True)
leftest_point = robots[0][0] - robots[0][1] + 1
ans = 0
for i in range(1, len(robots)):
    if robots[i][0]+robots[i][1] - 1 > leftest_point:
        ans += 1
        continue
    else:
        leftest_point = robots[i][0]-robots[i][1] + 1
second = N-ans

print(max(first, second))

Submission status: Wrong Answer

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

#print(xl)
xl.sort()
#print(xl)
#exit()

#kazu = 2*10**9

plus = []
minus = []

for i in range(n):
    plus.append(xl[i][0]-xl[i][1]+1)
    minus.append(xl[i][0]+xl[i][1]-1)

#plus.sort()
#minus.sort()

num = 0
ima = n

for i in range(n-1):
    if minus[i]  > plus[i+1]:
        ima -= 1
        
print(ima)

Submission status: Wrong Answer

Solution code:
# N個のロボット
N = int(input())

# 1個前
rem = 0
bx = 0
bl = 0
for i in range(N):
    x,l = map(int, input().split())
    
    #print(x,l, bx,bl)
    
    # 1個前と重複確認
    if i != 0:
        
        # 1個前と比べて、範囲が重複してなければOK
        #print(bx - bl+1 , bx , bx+bl-1 , x-l+1 , x , x+l-1)
        if (bx - bl+1 <= bx <= bx+bl-1 < x-l+1 <= x <= x+l-1):
            # 1個前を更新
            bx = x
            bl = l
        else:
            #print("rem")
            rem +=1
            # 1個前は変えないで次へ
            continue

    else:
        # 1個前を更新
        bx = x
        bl = l
    

print(N-rem)

Submission status: Wrong Answer

Solution code:
#python3
import operator as op
n = int(input())
a = []
for _ in range(n):
    x, l = map(int, input().split())
    a.append((x,l))

a.sort(key=op.itemgetter(0))

MAX = -int(1e11)
cnt = 0
for i in range(n):
    x, l = a[i]
    MIN = x - l
    if MAX > MIN:
        pass
    else:
        cnt +=1
        MAX = x+l
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
t = [input().split() for i in range(n)]
t = [[int(i) for i in j] for j in t]
t = sorted(t)
delcount,counter = 0,t[0][0]+t[0][1]
for i in range(1,n):
	if counter > t[i][0] - t[i][1]:
		delcount+=1
	else:
		counter = t[i][0] + t[i][1]
p = n - delcount

delcount,counter = 0,t[n-1][0]+t[n-1][1]

for i in range(n-1,0,-1):
	if counter < t[i][0] + t[i][1]:
		delcount+=1
	else:
		counter = t[i][0] - t[i][1]
print(max(p,n - delcount))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
if n==1:
  print(1)
elif n==2:
  for i in range(n-1):
    if l[i][0]+l[i][1]>l[i+1][0]-l[i+1][1]:
      print(1)
    else:
      print(2)
else:
  ans=0
  for i in range(1,n-1):
    if l[i][0]+l[i][1]>l[i+1][0]-l[i+1][1]:
      ans+=1
      if l[i-1][0]+l[i-1][1]>l[i+1][0]-l[i+1][1]:
        ans+=1
  print(n-ans)

Submission status: Wrong Answer

Solution code:
num = int(input())
j = 0
counter = 0

input_l = []

for i in range(num):
    a = input().split(" ")
    input_l.append(a)

while True:
    temp = input_l
    for i in range(len(input_l) - 1):
        if int(input_l[i][0]) > int(input_l[i+1][0]):
            x = input_l[i]
            input_l[i] = input_l[i+1]
            input_l[i+1] = x
    if temp == input_l:
        break


while True:
    if j == len(input_l) - 1:
        break
    if (int(input_l[j][0]) + int(input_l[j][-1])) - (int(input_l[j+1][0]) - int(input_l[j+1][-1])) > 0:
        counter += 1
        del input_l[j+1]
    else:
        j += 1

print(num - counter)

Submission status: Wrong Answer

Solution code:
import numpy as np

N=int(input())
#A=[int(x) for x in input().split()]
XL=[]
for i in range(N):
    XL.append(list(map(int,list(input().split()))))
XL=np.asarray(XL)
XLs=XL[np.argsort(XL[:,0])]
right=XLs[0][0]+XLs[0][1]
ans=1
for i in range(N-1):
    if XLs[i+1][0]-XLs[i+1][1]-right>=0:
        ans+=1
        right=XLs[i+1][0]-XLs[i+1][1]
    elif XLs[i+1][0]+XLs[i+1][1]-(XLs[i][0]+XLs[i][1])<0:
        right=XLs[i+1][0]+XLs[i+1][1]
#ans=XLs
print(ans)

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:
    x1, l1 = robots[p]
    x2, l2 = robots[q]
    if ok[p] and not x1 + l1 <= x2 - l2:
        ok[q] = False
    
    p = q
    q = p + 1

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

Submission status: Wrong Answer

Solution code:
N = int(input())
input_list = []
lobot_list = []
for i in range(N):
    tmp = input()
    tmp_list = tmp.split()

    a = int(tmp_list[0])
    b = int(tmp_list[1])
    
    lobot_list.append(a)
    #lobot_list.append(b)
    lobot_list.append(a+b)

"""
    x1 = a + b
    x2 = a - b

    lobot_list.append(x1)
    lobot_list.append(x2)
"""



#print(lobot_list)

count = 0
for i in range(N):
    if(lobot_list[i] > lobot_list[i+1]):
        count = count + 1
print(N-count)