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


print(ans)

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:
    maxs = x[i][0] + x[i][1]
    ming = x[i + 1][0] - x[i + 1][1]
    if maxs > ming:
        del x[i + 1]
        ans -= 1
        i -= 1
    i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
def search_touched_idx(i, val, l):
    ret = []
    base_idx = val[0]
    arm_length = val[1]
    if arm_length != 0:
        minus_idx = base_idx - arm_length
        plus_idx = base_idx + arm_length
        for n in range(i-1, 0, -1):
            if minus_idx < l[n][0]:
                ret.append(n)
            else:
                break

        for n in range(i+1, len(l)):
            if l[n][0] < plus_idx:
                ret.append(n)
            else:
                break
    return ret

N = int(input().rstrip())
l = []
for i in range(N):
    l.append(list(map(int ,input().rstrip().split())))
# print(l)

touch = []  # stored touched idx to list
l.sort(key=lambda x: x[0])
count = 0
prev_robot_touched = False
for i, val in enumerate(l):
    # touch.append(search_touched_idx(i, val, l))
    tmp = len(search_touched_idx(i, val, l))
    if tmp and not prev_robot_touched:
        prev_robot_touched = True
        count += 1
    else:
        prev_robot_touched = False
# print(touch)
print(len(l) - count)

Submission status: Wrong Answer

Solution code:
n = int(input())
result = n
a,b = input().split()
min = int(a) - int(b)
max = int(a) + int(b)

for i in range(n-1):
    a,b = input().split()
    l1 = int(a) - int(b)
    l2 = int(a) + int(b)
    if min <= l2:
        if l1 < max:
            result = result - 1
        else:
            min = int(a) - int(b)
            max = int(a) + int(b)
    else:
        if l1 > max:
            result = result - 1
        else:
            min = int(a) - int(b)
            max = int(a) + int(b)
print(result)

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(A,B)
k = sorted(k, key=lambda x:(x[0], x[1]))
c=1
ans=[]
ans.append((k[0][0],k[0][1]))

max_=k[0][1]
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][0],k[i][1])
    if x[0] >= max_:
        c+=1
        max_=x[0]
    #print(c,max_,x)
print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())
R=[list(map(int,input().split())) for i in range(N)]
bf = 0
ans = N
R = sorted(R)

for i in range(N-1):
  up = 1
  down = 1
  if R[bf][0] + R[bf][1] - 1 >= R[i+1][0] - R[i+1][1] + 1:
    for j in range(i+2,N-1):
      if R[bf][0] + R[bf][1] - 1 >= R[j][0] - R[j][1] + 1:
        up += 1
      else:
        break
    for j in range(i)[::-1]:
      if R[j][0] + R[j][1] - 1 >= R[i+1][0] - R[i+1][1] + 1:
        down += 1
      else:
        break
    if up >= down:
      ans = ans - down
      bf = i
    else:
      ans = ans - up
      bf = i + 1
  else:
    bf = i+1
  if ans == 0:
    break
  
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
r = -100000000#ひとつ前の右手の到達範囲（プラス方向）
l = -100000000#ひとつ前の左手の到達範囲（マイナス方向）
narabi = {}
count = []#取り除く機械番号
for i in range(N):
  X,L = map(int,input().split())
  narabi[X]=L
jyunban = sorted(narabi.items())

for j in range(N):
  migi = jyunban[j][0]+jyunban[j][1]
  hidari = jyunban[j][0]-jyunban[j][1]
  if r > hidari:#ぶつかる場合
    count.append(str(j+1))
  else:
    l = hidari
    r = migi
toru = len(count)
print(N-toru)

Submission status: Wrong Answer

Solution code:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N = int(input())
    X = []
    L = []
    XL = []
    for i in range(N):
        temp = list(map(int,input().split()))
        XL.append([temp[0]-temp[1],temp[1]*2])

    XL.sort()

    res = 0
    end = - 10 ** 9

    for i in range(N):
        if end <= XL[i][0]:
            res += 1
            end = XL[i][0] + XL[i][1]

    print(res)



main()

Submission status: Wrong Answer

Solution code:
#-*- coding: utf-8 -*-
from collections import defaultdict
import sys
import math
from datetime import datetime
import re
import math
def sol(n, X, L):
    Cs = []
    for i in range(n):
        Cs.append( (X[i] - L[i], X[i] + L[i] ) )
    mini = sys.maxsize
    m, n = None, None
    counter = 0
    Cs.sort(key=lambda x : x[0])
    for a, b in Cs:
        if m is None:
            counter += 1
        elif a <= m and n <= b:
            counter += 1
        elif n <= a:
            counter += 1
        # 被っている部分の更新
        if m is None: m, n = a, b
        elif b < n: m, n = min(b, n), n
        elif a < n: m, n = n, b
        else: m, n = max(a,n), b
    return counter





do_submit = True
#do_submit = False

def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(map(str, line.split())) for line in lines]
    print(parsed_lines)
    # n = int(parsed_lines[0][0])
    # k = int(parsed_lines[0][1])
    S = parsed_lines[0][0]
    return S


if not do_submit:
    S = input_parse("""
    1905
    """)
    print(sol(S))

    S = input_parse("""
    0112
    """)
    print(sol(S))

    S = input_parse("""
    1700
    """)
    print(sol(S))

    S = input_parse("""
    0000
    """)
    print(sol(S))

    S = input_parse("""
    1001
    """)
    print(sol(S))



else:
    #A, B = list(map(int, input().split()))
    n = int(input())
    X = []
    L = []
    for i in range(n):
        x, l = list(map(int, input().split()))
        X.append(x)
        L.append(l)

    print(sol(n, X, L))

    # S = input().strip()
    # print(sol(S))

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
l0, r0 = Y[0]
for i in range(1, n):
    l, r = Y[i]
    if r0 >= l:
        cnt += 1
        if r0 > r:
            l0, r0 = l, r
print(n-cnt)

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)
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
second = N-ans

print(max(first, second))

Submission status: Wrong Answer

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

def main():
    def have_common(di, dj):
        """2つの区間di, djが共通部分を持つかどうかを判定
        """
        if dj[0] < di[0]:
            di, dj = dj, di
        if dj[0] < di[1]:
            return True
        else:
            return False


    N = int(input())

    X, L, D = [0] * N, [0] * N, [[0, 0]] * N
    for i in range(N):
        X[i], L[i] = map(int, input().split())
        D[i] = [[X[i]-L[i], X[i]+L[i]], L[i]]

    # 区間の長さが小さいものからみる
    D.sort(key=lambda x:x[1])

    ans = N
    j = 0
    while (j < len(D) - 1):
        k = j + 1
        while (k < len(D)):
            if have_common(D[j][0], D[k][0]):
                D.remove(D[k])
                ans -= 1
            else:
                k += 1
        j += 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

#output
import bisect as bi
import numpy as np

M = np.array((X, L))

M = np.sort(M, axis = 1)

sum = 1
worm = M[0, 0] + M[1, 0]
while worm <= M[0, N-1]:
    worm = bi.bisect_left(M[0], worm)
    worm = M[0, worm] + M[1, worm]
    sum += 1

print(sum)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N= int(input())
ans = 1
a = []

for i in range(N):
    tmpa, tmpb = map(int,input().split())
    a.append([tmpa+tmpb, tmpa-tmpb])

a.sort()
    
tmp = a[0][1]
for i in range(1, N):
    if a[i][0] >= tmp:
        ans += 1
        tmp = a[i][1]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

x = []
for i in range(n):
    x1, y1=[int(i) for i in input().split()]
    x.append([x1, y1])

x.sort()

remove = 0
stocks = 0

for k in range(n - 1):
    if k+1+stocks < n:
  	    if (x[k + 1 + stocks][0] - x[k][0]) < x[k][1] + x[k + 1][1]:
              remove += 1
              x[k + 1][0] = -1
              if n - 2 > k:
                  stocks += 1
              k -=1
  	    else:
              stocks=0

print (n -remove)

Submission status: Wrong Answer

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

n = int(input())

# a = [[0]*2 for _ in range(n)]
# for i in range(n):
#     a[i][0], a[i][1] = map(int, input().split())


a = [[0]*2 for _ in range(n)]

for i in range(n):
    a_temp, x_temp = map(int, input().split())

    a[i][0] = a_temp + x_temp - 1
    a[i][1] = a_temp - x_temp + 1

# print(a)
a.sort()
# print(a)
ans = n
temp = a[0][0]
for i in range(1, n):
    if temp >= a[i][1]:
        ans -= 1
    else:
        temp = a[i][0]
# print(ans)
t = ans
ans = n
sorted(a, key=lambda x:(x[1]), reverse=True)
temp = a[-1][1]
for i in range(n-1, -1, -1):
    if temp <= a[i][0]:
        ans -= 1
    else:
        temp = a[i][1]
print(max(ans, t))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
for i in range(n):
    xl = list(map(int,input().split()))
    a.append(xl)
#print(a)
b = sorted(a)
#print(b)
count = 0
j =  0

for i in range(n-1):
    if j != 0:
        j = 0
        break
#if b[i][0] + b[i][1] > b[i+2][0] - b[i+2][1]:
    #if i <= n-3 and b[i-1][0] + b[i-1][1] > b[i+1][0] - b[i+1][1]:
    #    count -= 1
    #if i > 0 and b[i-1][0] + b[i-1][1] > b[i][0] - b[i][1]:
    #    count -= 1
    ude_mae = b[i][0] + b[i][1]
    ude_ushiro = b[i+1][0] - b[i+1][1]

    if i != n-2 and ude_mae > ude_ushiro:
        count += 1
        j += 1
    #print(i)
        #if i > 0 and b[i-1][0] + b[i-1][1] > b[i][0] - b[i][1]:
        #    count -= 1
        #if i <= n-3 and b[i][0] + b[i][1] > b[i+2][0] - b[i+2][1]:
        #    count -= 1
    #elif b[i][0] + b[i][1] > b[i+1][0] - b[i+1][1]:
    #    count += 1
    #    i += 1
#print(count)
ans = n - count
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter, attrgetter
def solve():
    def f(x, l):
        return [x, l - 1]
    n = int(input())
    B = [1] * n
    XL = sorted(f(*list(map(int, input().split()))) for _ in range(n))
    XL2 = sorted([[x, l, i] for i, [x, l] in enumerate(XL)], key=itemgetter(1), reverse=True)
    ans = n
    for x, l, i in XL2:
        if B[i] == 0:
            continue
        if 0 < i and B[i - 1] and XL[i - 1][0] + XL[i - 1][1] >= x - l:
            B[i] = 0
            ans -= 1
        elif i < n - 1 and B[i + 1] and x + l >= XL[i + 1][0] - XL[i + 1][1]:
            B[i] = 0
            ans -= 1
    print(ans)
solve()

Submission status: Wrong Answer

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

X.sort(key=lambda x: x[2])  # 端点順
removed = [False] * N

for i in range(N - 1):
    if removed[i]:
        continue
    x, l, rl, rr = X[i]
    for j in range(i + 1, N):
        if removed[j]:
            continue
        if rr <= X[j][2]:
            if l < X[j][1]:
                removed[j] = True
            else:
                removed[i] = True
        else:
            break

print(N - sum(removed))

Submission status: Wrong Answer

Solution code:
N = int(input())
X = []
L = []
for i in range(N):
    a, b = map(int,input().split())
    X.append(a)
    L.append(b)
l = dict()
for i in range(N):
    l[X[i]] = L[i]
X.sort()
R = dict()
flag = dict()
for i in range(N):
    R[X[i]] = X[i] + l[X[i]]
    R[-X[i]] = X[i] - l[X[i]]
    flag[X[i]] = 0

for i in range(1,N-1):
    if i > 1:
        #3個以上侵食する奴ら
        if (R[X[i-2]] > R[-X[i]]): #or (R[X[i]] > R[-X[i+2]]):
            flag[X[i]] = 2
            continue
    if i < (N-3):
        if (R[X[i]] > R[-X[i+2]]):
            flag[X[i]] = 2
            continue
    #2個以上侵食する奴ら
    if (R[X[i-1]] > R[-X[i]]) and (R[X[i]] > R[-X[i+1]]):
        flag[X[i]] = 2
        continue
        #1個侵食する奴ら
    if (R[X[i-1]] > R[-X[i]]) or (R[X[i]] > R[-X[i+1]]):
        if flag[X[i]] == 0:
            flag[X[i]] = 1
#X[0]とX[N-1]の扱い
lenx = len(X)
if lenx > 2:
    if R[X[0]] > R[-X[2]]:
        flag[X[0]] = 2
if lenx > 1:
    if R[X[0]] > R[-X[1]]:
        if flag[X[0]] == 0:
            flag[X[0]] = 1
if lenx > 2:
    if R[X[N-3]] > R[X[N-1]]:
        flag[X[N-1]] = 2
if lenx > 2:
    if R[X[N-2]] > R[X[N-1]]:
        if flag[X[N-1]] == 0:
            flag[X[N-1]] = 1
while(1):
    fl = 0
    del2_list = []
    del2 = 0
    for i in range(len(X)):
        if flag[X[i]] != 2:
            del2_list.append(X[i])
        else:
            del2 = 1
            flag[X[i]] = -1
    if del2 > 0:
        X = del2_list
        X.sort()
    del1_list = []
    del1 = 0
    if del2 == 0:
        for i in range(len(X)-1):
            if flag[X[i]] != 1:
                del1_list.append(X[i])
            else:
                if flag[X[i+1]] == 1:
                    del1_list.append(X[i])
                del1 = 1
                flag[X[i]] = -1
        lenx = len(X)
        #len(X)-1の処理
        if lenx > 0:
            if flag[X[len(X)-1]] != 1:
                del1_list.append(X[len(X)-1])
            else:
                del1 = 1
                flag[X[len(X)-1]] = -1
        if del1 > 0:
            X = del1_list
            X.sort()


    R_2 = dict()
    for i in range(len(X)):
        R_2[X[i]] = X[i] + l[X[i]]
        R_2[-X[i]] = X[i] - l[X[i]]
        flag[X[i]] = 0
    for i in range(1,len(X)-1):
        if (R_2[X[i-1]] > R_2[-X[i]]) or (R_2[X[i]] > R_2[-X[i+1]]):
            if flag[X[i]] == 0:
                flag[X[i]] = 1
    if len(X) > 2:
        if R_2[X[0]] > R_2[-X[1]]:
            if flag[X[0]] == 0:
                flag[X[0]] = 1
    if len(X) > 2:
        if R_2[X[len(X)-2]] > R_2[X[len(X)-1]]:
            if flag[X[N-1]] == 0:
                flag[X[N-1]] = 1

    for i in range(len(X)):
        if flag[X[i]] > 0:
            fl = 1
    if fl == 0:
        break
ans = len(X)
if ans == 0:
    ans = 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
p = []
for _ in range(N):
    x, n = [int(i) for i in input().split()]
    p.append((x-n, x+n))
p.sort()
cc = [0 for _ in range(N)]
i = 0
j = 1
c=0
while i<N and j<N:
    # print(p[i][0],p [j][0], p[i][1])
    if p[i][0]<=p[j][0]<p[i][1]:
        # print("!")
        j+=1
        cc[j-1]+=1
        cc[i]+=1
    else:
        i+=1
        j=i+1
co=[int(i>1) for i in cc]
# print(co)
if all([i==0 for i in co]):
    # print("!")
    if all([i==0 for i in cc]):
        print(N)
    else:
        print(1)
    quit()
print(N-sum(co))

Submission status: Wrong Answer

Solution code:
from itertools import groupby
from operator import itemgetter
import numpy as np
N = int(input())
arm = []
for i in range(N):
  x, l = map(int, input().split())
  a = [x-l+1, x+l-1]
  arm.append(a)
arm = sorted(arm, key=lambda x: x[1])
now = arm[0][1]
count = 1
for i in range(1,N):
  if now < arm[i][0]:
    count += 1
    now = arm[i][1]
print(count)

Submission status: Wrong Answer

Solution code:
def search_touched_idx(i, val, l):
    ret = []
    base_idx = val[0]
    arm_length = val[1]
    if arm_length != 0:
        minus_idx = base_idx - arm_length
        plus_idx = base_idx + arm_length
        for n in range(i-1, 0, -1):
            if minus_idx < l[n][0]:
                ret.append(n)
            else:
                break

        for n in range(i+1, len(l)):
            if l[n][0] < plus_idx:
                ret.append(n)
            else:
                break
    return ret

N = int(input().rstrip())
l = []
for i in range(N):
    l.append(list(map(int ,input().rstrip().split())))
# print(l)

touch = []  # stored touched idx to list
l.sort(key=lambda x: x[0])
count = 0
for i, val in enumerate(l):
    # touch.append(search_touched_idx(i, val, l))
    tmp = len(search_touched_idx(i, val, l))
    if tmp:
        count += 1
# print(touch)
print(len(l) - count)

Submission status: Wrong Answer

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

tmp = sum(xl[0])

res = 0
for i in range(1, n):
    x, l = xl[i]
    if tmp-1 >= x-l+1:
        res += 1
    tmp = min(tmp, x+l)

print(n-res)

Submission status: Wrong Answer

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

n = int(input())

# a = [[0]*2 for _ in range(n)]
# for i in range(n):
#     a[i][0], a[i][1] = map(int, input().split())


a = [[0]*2 for _ in range(n)]

for i in range(n):
    a_temp, x_temp = map(int, input().split())

    a[i][0] = a_temp + x_temp - 1
    a[i][1] = a_temp - x_temp + 1

# print(a)
a.sort()
# print(a)
ans = n
temp = a[0][0]
for i in range(1, n):
    if temp >= a[i][1]:
        ans -= 1
    else:
        temp = a[i][0]
# print(ans)
t = ans
ans = n

temp = a[-1][1]
for i in range(n-1, -1, -1):
    if temp <= a[i][0]:
        ans -= 1
    else:
        temp = a[i][1]
print(max(ans, t))

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
lst=[]
for i in range(n):
  x,l=map(int,input().split())
  lst.append([x,l])
lst.sort(key=lambda x:x[0])
if n==1:
    print(1)
    sys.exit()
if n==2:
    if lst[1][0]-lst[1][1]<lst[0][0]+lst[0][1]:
        print(2)
        sys.exit()
    else:
        print(1)
        sys.exit()
i=0
if lst[i][0]+lst[i][1]>lst[i+2][0]-lst[i+2][1]:
    del lst[i]
i+=1
while i<len(lst)-2:
  if (lst[i][0]+lst[i][1]>lst[i+2][0]-lst[i+2][1]) or ((lst[i][0]-lst[i][1]<lst[i-1][0]+lst[i-1][1])and (lst[i][0]+lst[i][1]>lst[i+1][0]-lst[i+1][1])):
    del lst[i]
  else:
    i+=1 
if lst[i][0]-lst[i][1]<lst[i-1][0]+lst[i-1][1] and lst[i][0]+lst[i][1]>lst[i+1][0]-lst[i+1][1]:
    del lst[i]
j=0
while j<len(lst)-1:
  if lst[j][0]+lst[j][1]>lst[j+1][0]-lst[j+1][1]:
    del lst[j]
  else:
    j+=1
print(len(lst))

Submission status: Wrong Answer

Solution code:
n = int(input())
data = [[]]*(n+2)
data[0] = [0, 0]
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
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:
def have_common(di, dj):
    """2つの区間di, djが共通部分を持つかどうかを判定
    """
    if dj[0] < di[0]:
        di, dj = dj, di
    if dj[0] < di[1]:
        return True
    else:
        return False

N = int(input())

X, L, D = [0] * N, [0] * N, [[0, 0]] * N
for i in range(N):
    X[i], L[i] = map(int, input().split())
    D[i] = [[X[i]-L[i], X[i]+L[i]], L[i]]

# 区間の長さが小さいものからみる
D.sort(key=lambda x:x[1])

ans = N
j = 0
while (j < len(D) - 1):
    k = j + 1
    while (k < len(D)):
        if have_common(D[j][0], D[k][0]):
            D.remove(D[k])
            ans -= 1
        else:
            k += 1
    j += 1

print(ans)

Submission status: Wrong Answer

Solution code:
s=int(input())
t=[list(map(int, input().split())) for i in range(s)]
t.sort()
a=t[0][0]+t[0][1]
b=1
c=0
count1=1
count2=0
for i in range(1,s):
  c=t[i][0]-t[i][1]
  if a<=c:
    count1+=1
    a=t[i][0]+t[i][1]
a=t[0][0]+t[0][1]
d=0
for j in range(1,s):
  c=t[j][0]-t[j][1]
  if d==0:
    if a<=c:
      a=t[j][0]+t[j][1]      
    else:
      a=t[j][0]+t[j][1]
      count2+=1
      d+=1
  else:
    if a<=c:
      count2+=1
      a=t[j][0]+t[j][1]
if count1<count2:
  print(count2)
else:
  print(count1)

Submission status: Wrong Answer

Solution code:
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n = ni()
xl = [na() for i in range(n)]
xl.sort()
d = [(xl[i][0] - xl[i][1] + 1, xl[i][0] + xl[i][1] - 1) for i in range(n)]
p = [1 if i > 0 and d[i][0] <= d[i - 1][1] else 0 for i in range(n)]
for i in range(n - 1):
    if d[i + 1][0] <= d[i][1]:
        p[i] += 1

res = 0

for i in range(n):
    if p[i] <= 0: continue
    if p[i] >= (p[i - 1] if i > 0 else 0) + (p[i + 1] if i < n - 1 else 0):
        res += 1
        p[i] = 0
        if i > 0:
            p[i - 1] -= 1
        if i < n - 1:
            p[i + 1] -= 1

print(n - res)

Submission status: Wrong Answer

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

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

x, l = xl[0]
ans = n
for i in range(1, n):
    if l > xl[i][1]: 
        if (
            x-l+1 < xl[i][0]-xl[i][1] < x+l-1 or
            x-l+1 < xl[i][0]+xl[i][1] < x+l-1
            ):
                x, l = xl[i]
                ans -= 1
        else:
            x, l = xl[i]
    else:
        if (
            xl[i][0]-xl[i][1]+1 < x-l < xl[i][0]+xl[i][1]-1 or
            xl[i][0]-xl[i][1]+1 < x+l < xl[i][0]+xl[i][1]-1
            ):
                ans -= 1
        else:
            x, l = xl[i]

print(ans)

Submission status: Wrong Answer

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


N = int(input())
start = []
end = []
itv = []
for i in range(N):
    X, L = (int(i) for i in input().split())
    itv.append([X+L-1, X-L+1])
    #start.append(X-L)
    #end.append(X+L)

#XL = [[int(i) for i in input().split()] for i in range(N)] 

#line = [0] * (2*(10**9) +1)

itv.sort()

#print(itv)

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

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]):
      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+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())

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

LL=[]
LL.append(L[0])
bef=sum(L[0])
for i in range(1,n):
    if bef<=L[i][0]-L[i][1]:
        LL.append(L[i])
        bef=sum(L[i])
print(len(LL))

Submission status: Wrong Answer

Solution code:

def Key2():
    N = int(input())
    cnt = 0
    robotlist = []
    x, l = map(int, input().split())

    Lmin = x - l + 1
    Lmax = x + l - 1
    robotlist.append([Lmin, Lmax])
    for i in range(N - 1):
        x, l = map(int, input().split())
        flag = 'False'
        Lmin = x - l + 1
        Lmax = x + l - 1

        for r in robotlist:

            if r[0] <= Lmin <= r[1]:
                cnt += 1
                flag = 'True'
                continue
            elif r[0] <= Lmax <= r[1]:
                cnt += 1
                flag = 'True'
                continue
            elif r[0] <= x <= r[1]:
                cnt += 1
                flag = 'True'
                continue
            elif Lmin <= r[0] <= Lmax:
                cnt += 1
                flag = 'True'
                continue
        if flag == 'False':
            robotlist.append([Lmin, Lmax])



    print(N - cnt)

Key2()

Submission status: Wrong Answer

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

ans = [[0 for i in range(2)] for j in range(n)]
for i in range(n):
    ans[i][1]=(x[i]+l[i])
    ans[i][0]=max(0,x[i]-l[i])
ans.sort()
count=1
j=0
for i in range(n-1):
    if ans[j][1]<=ans[i+1][0]:
        count+=1
        j=i+1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

xl = sorted(xl)
max_cover = xl[0][1]
num_remove = 0
for i,t in enumerate(xl[1:]):
    if t[0] < max_cover:
        num_remove += 1
    else:
        max_cover = t[1]

print(N-num_remove)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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

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

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

ans.append(robs[0])

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

Submission status: Wrong Answer

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

n = int(input())

# a = [[0]*2 for _ in range(n)]
# for i in range(n):
#     a[i][0], a[i][1] = map(int, input().split())


a = [[0]*2 for _ in range(n)]

for i in range(n):
    a_temp, x_temp = map(int, input().split())

    a[i][0] = a_temp + x_temp - 1
    a[i][1] = a_temp - x_temp + 1

# print(a)
a.sort()
# print(a)
ans = n
temp = a[0][0]
for i in range(1, n):
    if temp >= a[i][1]:
        ans -= 1
    else:
        temp = a[i][0]
# print(ans)
t = ans
ans = n

temp = a[-1][1]
for i in range(n-1, 0, -1):
    if temp <= a[i][0]:
        ans -= 1
    else:
        temp = a[i][1]
print(max(ans, t))

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
		t[i][0],t[i][1] = 0,-1
	else:
		counter = t[i][0] + t[i][1]
print(n - delcount)

Submission status: Wrong Answer

Solution code:
n = int(input())
robot = []
for a in range(n):
    x,l = [int(i) for i in input().split()]
    index = 0
    i = 0
    while i < len(robot) and robot[i][0]-robot[i][1] < x + l:
        if robot[i][0] + robot[i][1] < x - l:
            i += 1
        else:
            temp = robot[i]
            if x-l < temp[0]-temp[1] < x+l or x-l < temp[0] < x+l or x-l < temp[0]+temp[1] < x+l:
                break
            i += 1
    else:
        robot.insert(i, [x,l])
# print(robot)
print(len(robot))

Submission status: Wrong Answer

Solution code:
def have_common(di, dj):
    """2つの区間di, djが共通部分を持つかどうかを判定
    """
    if dj[0] < di[0]:
        di, dj = dj, di
    if dj[0] < di[1]:
        return True
    else:
        return False

N = int(input())

X, L, D = [0] * N, [0] * N, [[0, 0]] * N
for i in range(N):
    X[i], L[i] = map(int, input().split())
    D[i] = [[X[i]-L[i], X[i]+L[i]], L[i]]
D.sort(key=lambda x:x[1])

ans = N
j = 0
while (j < len(D) - 1):
    k = j + 1
    while (k < len(D)):
        if have_common(D[j][0], D[k][0]):
            D.remove(D[k])
            ans -= 1
        else:
            k += 1
    j += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
data = [[]]*(n+2)
data[0] = [0, 0]
for i in range(1, n+1):
    x, l = map(int, input().split())
    data[i] = [max(0,x-l), x+l]
data[n+1] = [10**10, 10**10]
data.sort()
ans = n
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:
#input
N = int(input())
X = []
L = []
for i in range(N):
    X_temp, L_temp = map(int, input().split())
    X.append(X_temp)
    L.append(L_temp)

#output
import bisect as bi
import numpy as np

M = np.array((X, L))

M = np.sort(M, axis = 1)

sum = 1
worm = M[0, 0] + M[1, 0]
while worm < M[0, N-1]:
    worm = bi.bisect_left(M[0], worm)
    worm = M[0, worm] + M[1, worm]
    sum += 1

print(sum)

Submission status: Wrong Answer

Solution code:
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n = ni()
xl = [na() for i in range(n)]
xl.sort()
d = [(xl[i][0] - xl[i][1] + 1, xl[i][0] + xl[i][1] - 1) for i in range(n)]
p = [1 if i > 0 and d[i][0] <= d[i - 1][1] else 0 for i in range(n)]
for i in range(n - 1):
    if d[i + 1][0] <= d[i][1]:
        p[i] += 1

res = 0

print(p)
for i in range(n):
    if p[i] <= 0: continue
    if p[i] >= (p[i - 1] if i > 0 else 0) + (p[i + 1] if i < n - 1 else 0):
        res += 1
        p[i] = 0
        if i > 0:
            p[i - 1] -= 1
        if i < n - 1:
            p[i + 1] -= 1

print(p)
print(n - res)