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:
# -*- 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):
    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])

    ans = 0
    t = -INF
    for l, r in s:
        if t < l:
            ans += 1
            t = r

    return ans

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

    XL = [[-x, l] for x, l in XL]
    b = slv(N, XL)
    print(max(a, b))


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)

if n >= 2:
    i = 0
    while i < len(d)-1:
        if d[i][2] > d[i+1][2]:
            d.pop(i)
        else:
            i += 1

#print(d)

p_r = 10**10 + 1
p_l = -1 * (10**10 + 1)
ans = 0
flag = True
p = -1 * (10**10 + 1)
j = 0
for j in range(len(d)):
    i,l,r = d.pop(0)
    if l > p:
        ans += 1
        p = r
    #print(j,d,ans)

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
X=[]
L=[]
A=[]
B=[]
for _ in range(n):
    x,l=map(int,input().split())
    X.append(x)
    L.append(l)
    A.append(x-l)
    B.append(x+l)
k = zip(A,B,L)
k = sorted(k, key=lambda x:(x[1], x[0]))
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:
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

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

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


#ddprint(x)
#ddprint(l)

ok = [1]*n

for i in range(n-1):
    if x[i]+l[i] < x[i+1]+l[i+1]:
        break
    else:
        ok[i] = 0

while i<n-1:
    for j in range(i+1,n):
        if x[i]+l[i] > x[j]-l[j]:
            ok[j] = 0
        else:
            break
    i = j

print(sum(ok))

Submission status: Wrong Answer

Solution code:
n = int(input())
length = []
judge = [1 for i in range(n)]
for i in range(n):
  x,l = map(int, input().split())
  length.append([x-l,x+l])
while any(judge):
  length = sorted(length)
  for i in range(len(length)):
    if i == 0:
      judge[i] = 0
    elif i == len(length)-1:
      judge[i] = 0
    else:
      mi = length[i-1][1] - length[i][0]
      if mi < 0:
        mi = 0
      ma = length[i][1] - length [i+1][0]
      if ma < 0:
        ma = 0
      judge[i] = mi + ma

  if any(judge):
    rm = judge.index(max(judge))
    length.pop(rm)
    judge.pop(rm)

print(len(length))

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,L])
li=sorted(li,key=lambda x:x[0])
for i in range(n):
    if cnt>li[i][0]:
        ans+=1
    else:
        cnt=li[i][0]+li[i][1]*2
print(n-ans)

Submission status: Wrong Answer

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

N = int(input())
robot_number = 0
arm_ranges = []
for n in range(N):
    [x, l] = [int(i) for i in input().split()]
    minimum = x - l
    maximum = x + l
    arm_ranges.append((maximum, minimum))

# 腕の届く端が小さいもの順にソート
arm_ranges_sorted = sorted(arm_ranges)

print(arm_ranges_sorted)

(ma, mi) = arm_ranges_sorted[0]
now_max = ma
robot_number += 1
for arm_range in arm_ranges_sorted[1:]:
    (ma, mi) = arm_range
    if mi >= now_max:
        robot_number += 1
        now_max = ma

print(robot_number)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
rob = defaultdict(list)
for i in range(n):
    x,l  = map(int,input().split())
    rob[x] = [l,x-l,x+l]
rob = sorted(rob.items())
ans = n
for idx,(key,[l,left,right]) in enumerate(rob):
    if idx != 0:
        if r > left:
            ans -= 1
        r = min(r,right)
    else:
        r = right

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
XL = []
import numpy as np
for _ in range(N):
    XL.append([int(x) for x in input().split()])
XL = np.array(sorted(XL))
XL_max = []
dic = {}
for i in range(N):
    X, L = XL[i]
    dic[str(i)] = [X + L, X - L]
    XL_max.append(X + L)
XL_min = []
XL_max = sorted(XL_max)
A = [0] * N
from bisect import insort
import bisect
for i in range(N):
    XL_max.remove(dic[str(i)][0])
    cnt = 0
    cnt += i - bisect.bisect_right(XL_max, dic[str(i)][1]) 
    cnt += bisect.bisect_left(XL_min, dic[str(i)][0])
    bisect.insort(XL_min, dic[str(i)][1])
    A[i] = cnt
cnt = np.array(sorted(A, reverse=True), np.int64)
cnt = np.cumsum(cnt)
if cnt[-1] == 0:
    print(N)
else:
    print(N - (np.searchsorted(cnt, cnt[-1] // 2) + 1))

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
robots = []
left = []
cnt = [0] * n
for _ in range(n):
    xi, li = map(int, input().split())
    robots.append((xi - li, xi + li))
robots.sort()
for i in range(n):
    left.append(robots[i][0])

for i in range(n - 1):
    nr = robots[i][1]
    index = bisect.bisect_left(left, nr)
    diff = abs(i + 1 - index)
    cnt[i] = diff
    if cnt[i] > 1:
        cnt[i] = -1
    if diff == 1:
        cnt[i + 1] += 1
ans = n - cnt.count(-1) - cnt.count(1) // 2

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
X=[]
L=[]
A=[]
B=[]
for _ in range(n):
    x,l=map(int,input().split())
    X.append(x)
    L.append(l)
    A.append(x-l)
    B.append(x+l)
k = zip(A,B,L)
k = sorted(k, key=lambda x:(x[1], x[2]))
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:
import math
import sys

m=10**9 + 7 
sys.setrecursionlimit(1000010)
INF=10 ** 10
N = int(input())
XL = sorted([list(map(int,input().split())) for _ in range(N)])
# print(N,XL)

DP = [ INF for _ in range(N+1)]
DP[0] = -INF
for i in range(N):
    #print(DP)
    (x,l) = XL[i]
    # print(x,l)
    for j in range(1,i+1):
        if DP[j-1] > x -l:
            continue
        if ( DP[j-1]<= x -l and x + l < DP[j]):
                DP[j] = x + l
#print(DP)
for i in range(2,N+1):
    if DP[i] == INF:
        print(i-1)
        exit(0)
print(N)

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
cp = ans
maxs = 0
for i in range(n - 1):
    if cp == ans:
        maxs = max(maxs, x[i][0] + x[i][1])
    ming = x[i + 1][0] - x[i + 1][1]
    if ming < maxs:
        ans -= 1
    else:
        cp = ans

ans2 = n
cpp = ans2
mins = float("inf")
for i in reversed(range(1,n)):
    if cpp == ans2:
        mins = min(mins, x[i][0] - x[i][1])
    maxg = x[i - 1][0] + x[i - 1][1]
    if mins < maxg:
        ans2 -= 1
    else:
        cpp = ans2
print(max(ans,ans2))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
rob = defaultdict(list)
for i in range(n):
    x,l  = map(int,input().split())
    rob[x] = [l,x-l,x+l]
rob = sorted(rob.items())
print(rob)
ans = n
for idx,(key,[l,left,right]) in enumerate(rob):
    if idx != 0:
        if r > left:
            ans -= 1
        r = min(r,right)
    else:
        r = right

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
robot=[]
for i in range(n):
    xl=list(map(int,input().split()))
    robot.append(xl)
robot.sort()
count=0
for i in range(1,n-2):
    if robot[i][0]+robot[i][1]>robot[i+1][0]-robot[i+1][1] and robot[i][0]-robot[i][1]<robot[i-1][0]+robot[i-1][1]:
        count+=1
        robot[i][0]=-100000000000
        robot[i][1]=0
robot.sort()
for i in range(n-1):
    if robot[i][0]+robot[i][1]>robot[i+1][0]-robot[i+1][1]:
        count+=1
print(n-count)

Submission status: Wrong Answer

Solution code:
N = int(input())
lst = sorted([list(map(int, input().split(" "))) for _ in range(N)], key=lambda x:x[0])

count = N
tmp = 0
for i in range(1, N):
  a = lst[i-1][0] + lst[i-1][1]
  b = lst[i][0] - lst[i][1]
  if i == tmp:
    continue
  if a > b:
    tmp = i + 1
    count -= 1

print(count)

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,L)
k = sorted(k, key=lambda x:(x[0], x[2]))
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:
import numpy as np
n = int(input())
robot = [
    list(map(int, input().split())) for i in range(n)
]
robot.sort(key=lambda x: x[1], reverse=True)
ans = 0
now = np.zeros(n, dtype="float32")

for i in range(n):
    robot_i = robot[i]
    a, l = robot_i
    if sum(now[a-l:a+l]) == 0:
        now[a-l:a+l] += 1
        ans += 1
print(ans)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())

robo = []

for i in range(n):
    a = list(map(int, input().split()))
    robo.append(a)

s = set(range(n))

nr = []

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

for i in s:
    a, b = r[i]
    flag = True
    for j in s:
        if j == i:
            continue
        x, y = r[j]
        if a + b < x:
            break
        if a-b < x-y and x+y < a+b:
            flag = False
            break
    
    if flag:
        nr.append(r[i])

count = 0

print(len(nr))

Submission status: Wrong Answer

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

x = sorted(x_org, key=lambda z: int(z[0]))
removed = 0
for i in range(1, n):
    if int(x[i][0]) - int(x[i][1]) < 0:
        removed += 1
        x[i] = x[i-1]
        continue
    else:
        before = int(x[i][0]) - int(x[i][1])
    if (int(x[i-1][0]) + int(x[i-1][1])) > 1000000000:
        removed += 1
        x[i] = x[i-1]
        continue
    else:
        after = int(x[i-1][0]) + int(x[i-1][1]) 
    if before < after:
        removed += 1
        x[i] = x[i-1]

print(n - removed)

Submission status: Wrong Answer

Solution code:
N=int(input())

a=[]
k=[]

for i in range(N):
    m=input().split()
    k=[int(m[0]),int(m[1])]
    a.append(k)

a=sorted(a)
#print(a)
counter=0
now=[]
out=0
for i in a:
    if counter==0:
        now=[i[0]+i[1]]
        counter+=1
        continue
    if now[0]>(i[0]-i[1]):
        out+=1
        continue
    if now[0]>i[0]:
        out+=1
        continue
    now[0]=i[0]+i[1]
print(len(a)-out)

Submission status: Wrong Answer

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

lr = []
for i in range(n):
    l = max(xl[i][0] - xl[i][1], 0)
    r = max(xl[i][0] + xl[i][1], 0)
    lr.append([r - l, l, r])

lr = sorted(lr)
cnt = 0

while cnt < n:
    for j in range(1, len(lr)):
        if lr[j - 1][1] == lr[j][1] or lr[j - 1][2] == lr[j][2]:
            lr.pop(j)
            break
        elif lr[j - 1][1] < lr[j][1] < lr[j - 1][2]:
            lr.pop(j)
            break

    cnt += 1

print(len(lr))

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.pop(index+1)
  
print(len(s))

Submission status: Wrong Answer

Solution code:
N = int(input())
robot = []

for i in range(N):
    x,l = map(int,input().split())
    robot.append([x,l])
    
robot.sort()
use = [0]*N
i = 0

while i < N-1:
    #print(i,"called")
    min_j = i
    min_pos = robot[i][0] + robot[i][1]
    if (robot[i][0] + robot[i][1]) <= (robot[i+1][0] - robot[i+1][1]):
        #print(i, "pass")
        use[i] = 1
        if i == N-2:
            use[N-1] = 1
            break
        i += 1

    else:
        for j in range(i+1,N):
            if (robot[i][0] + robot[i][1]) <= (robot[j][0] - robot[j][1]):
                break
            else:
                if min_pos > robot[j][0] + robot[j][1]:
                    min_pos = robot[j][0] + robot[j][1]
                    min_j = j
        use[min_j] = 1
        #print(i, min_j, j)
        if i == min_j:
            if j != N-1:
                i = j
            else:
                if min_j <= robot[N-1][0]-robot[N-1][1]:
                    use[N-1] = 1
                    break
                else:
                    break
        else:
            i = min_j
        

print(sum(use))
#print(use)

Submission status: Wrong Answer

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

def has_duplicates(seq):
    return len(seq) != len(set(seq))

from itertools import combinations

X = sorted(X)

ans = 1
for n in range(len(X), 0, -1):
    for x in combinations(X, n):
        # print(x)
        z = []
        for _x in x:
            z += _x
        print(n, z, has_duplicates(z))
        if not has_duplicates(z):
            if n > ans:
                ans = n
            break
            # print(x)
            # break

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
move = []
for i in range(N):
    X,L = map(int,input().split())
    move.append([X-L,X+L])
move = sorted(move, key=lambda x:(x[0],x[1]))

if N > 1:    
    i = 1
    while(len(move) > i+1):
        if move[i-1][0] == move[i][0]:
            del move[i-1]
        else:
            if move[i+1][0] <= move[i-1][1]:
                del move[i]
            else:
                i += 1
    if move[len(move)-2][1] >= move[len(move)-1][1]:
        print(len(move)-1)
    else:
        print(len(move))

Submission status: Wrong Answer

Solution code:
n = int(input())

import numpy as np

i_list = np.zeros((2,n), dtype = int)

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

# print(np.argsort(i_list[0,:]))

i_list_sorted = i_list[:, np.argsort(i_list[0, :])]

# print(i_list_sorted)

ans = 1
x = i_list_sorted[0, 0]
l = i_list_sorted[1, 0]
l_max = x + l - 1

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

Submission status: Wrong Answer

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

if n == 1:
  print(n)
else:
  XL = sorted(X, key=lambda x: x[0])

  wkans = 0
  idx = 0
  m = 1

  while idx+m < n:
    if XL[idx][3] < XL[idx+m][2]:
      idx += m
      m = 1
      # if idx+m > n-1:
      #   break
    else:
      if XL[idx][1] < XL[idx+m][1]:
        m += 1
        wkans += 1
        # if idx+m > n-1:
        #   break
      else:
        idx += m
        m = 1
        wkans += 1
        # if idx+m > n-1:
        #   break

  print(n-wkans)




# 1 10  -9 11
# 8 20 -12 28

Submission status: Wrong Answer

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

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

arm_limit_1 = []
arm_limit_1.append([robot[0][0]-robot[0][1]+1, robot[0][0]+robot[0][1]-1])
for i in range(1, N):
    limit_left_i = robot[i][0]-robot[i][1]+1
    limit_right_i = robot[i][0]+robot[i][1]-1
    if limit_left_i > arm_limit_1[-1][1]:
        arm_limit_1.append([limit_left_i, limit_right_i])

arm_limit_2 = []
arm_limit_2.append(arm_limit_1[-1])
for i in range(1, len(arm_limit_1)):
    if arm_limit_1[-(i+1)][1] < arm_limit_2[0][1]:
        arm_limit_2.insert(0, arm_limit_1[-(i+1)])

print(len(arm_limit_2))

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    xls_input = [[int(k) for k in input().split(" ")] for n in range(N)]
    xls_input.sort()
    #print(xls_input)

    xls = []
    ans = N
    seq = 0
    for i in range(N):
        xl = xls_input[i]
        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 seq == 0:
                if x - x_before < l + l_before:
                    ans -= 1
                    seq = 1
                else:
                    xls.append(xl)
                    seq = 0
            elif seq == 1:
                if x - x_before < l + l_before:
                    del xls[-1]
                    xls.append(xls_input[i-1])
                    xl_before = xls[-1]
                    x_before = xl_before[0]
                    l_before = xl_before[1]
                    if x - x_before < l + l_before:
                        ans -= 1
                        seq = 0
                else:
                    xls.append(xl)
                    seq = 0              
        #print(xls)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())

X_t=[]
L_t=[]
ans=0

for _ in range(N):
    x,l=map(int,input().split())
    X_t.append(x)
    L_t.append(l)

tmp=zip(X_t,L_t)
XL=sorted(tmp)

X=[]
L=[]

for x,l in XL:
    X.append(x)
    L.append(l)
    

nls=[0]
for i in range(1,N-1):
    if (X[i]+L[i]>X[i+1]-L[i+1]) and (X[i]-L[i]<X[i-1]+L[i-1]):
        ans+=1
    else:
        nls.append(i)
nls.append(N-1)
        
for i in range(len(nls)-1):
    if nls==[]:
        break
    if len(nls)==1:
        break
    if (i-2)>len(nls):
        break
    
    if X[nls[i]]+L[nls[i]]>X[nls[i+1]]-L[nls[i+1]]:
        ans+=1

print(N-ans)

Submission status: Wrong Answer

Solution code:
N=int(input())

a=[]
k=[]

for i in range(N):
    m=input().split()
    k=[int(m[0]),int(m[1])]
    a.append(k)

a=sorted(a)
#print(a)
counter=0
now=[]
out=0
for i in a:
    if counter==0:
        now=[i[0]+i[1]]
        counter+=1
        continue
    if now[0]>(i[0]-i[1]):
        out+=1
        continue
    now[0]=i[0]+i[1]
print(len(a)-out)

Submission status: Wrong Answer

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

# 1個前
rem = 0


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

#ソート
X.sort()


bx = 0
bl = 0
for i in range(N):
    
    x = X[i][0]
    l = X[i][1]
    #rint(x, l)
    
    # 1個前と重複確認
    if i != 0:
        
        # 1個前と比べて、範囲が重複してなければOK
        #rint(bx - bl+1 , bx , bx+bl-1 , x-l+1 , x , x+l-1)
        # 1個前の方が小さい時                        or 1個前の方が大きい時
        if (bx - bl+1 <= bx+bl-1 < x-l+1 <= x+l-1) or (x-l+1 <= x+l-1 < bx - bl+1 <= bx+bl-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:
n = int(input())
r = [[0,0]] * n
x_max = 10**9

for i in range(n):
  x, l = map(int, input().split())
  r[i] = [x, l]
# print(r)
r.sort()
# print(r)

ans = 0
end = -1
for i in range(n):
  x = r[i][0]
  l = r[i][1]
  current_start = x - l + 1
  if current_start < 0:
    current_start = 0
  
  current_end = x + l - 1
  if current_end > x_max:
    current_end = x_max
  
  ans += 1
  if end == -1:
    # first robot
    end = current_end
    continue
  if current_start <= end:
    ans -= 1
    if current_end < end:
      end = current_end
  else:
    end = current_end
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
dat = []
for _ in range(n):
    x, l = map(int, input().split())
    #           0  1   2    3    4co     5
    dat.append([x, l, x-l, x+l, 0     , collections.deque([])])
dat.sort(key = lambda x: x[1], reverse=True)
res = []
def do_count():
    for i in range(n):
        #print("i={0}".format(i))
        for j in range(i+1, n):
            #print("j={0}".format(j))
            if dat[j][3] <= dat[i][2] or dat[i][3] <= dat[j][2]:
                pass
            else:
                dat[i][5].append(dat[j])
                dat[j][5].append(dat[i])
                dat[i][4] += 1
                dat[j][4] += 1

do_count()
#dat.sort(key = lambda x: (x[4], x[1]), reverse=True)
#print(dat)
for i in range(n):
    if dat[i][4] == 0:
        res.append(dat[i])
        continue
    #print("node {0}: kill".format(i))
    """
    for node in dat[i][5]:
        #print(node[5])
        for x in range(len(node[5])):
            if node[5][x] == dat[i]:
                node[4] -= 1
                del node[5][x]
                #print("!!!!")
    """

#print(res)
print(len(res))

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

    ans = 0
    t = -INF
    for l, r in s:
        if t < l:
            ans += 1
            t = r

    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:
import itertools
N = int(input())
robots = []
for _ in range(N):
    robots.append(list(map(int, input().split())))

print(robots)
Xn = robots[N-1][0]

all_robots = [i for i in range(N)]

combinations_okay = []
sums = []
for x in range(1, N+1):
    all_combinations = list(itertools.combinations(all_robots, x))
    print(all_combinations)

    sum = 0
    for item in all_combinations:
        isPlacable = True
        for i in range(len(item) - 1):
            if robots[item[i]][0] + robots[item[i]][1] > robots[item[i+1]][0] - robots[item[i+1]][1]:
                isPlacable = False

        if isPlacable:
            combinations_okay.append(len(item))

print(combinations_okay)
print(max(combinations_okay))

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

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

ans = 0
t = -10**10
for i in range(N):
    if t < XL[i][0]:
        ans += 1
        t = XL[i][1]
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    xls_input = [[int(k) for k in input().split(" ")] for n in range(N)]
    xls_input.sort()
    #print(xls_input)

    xls = []
    ans = N
    seq = 0
    for i in range(N):
        xl = xls_input[i]
        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 seq == 0:
                if x - x_before < l + l_before:
                    ans -= 1
                    seq = 1
                else:
                    xls.append(xl)
                    seq = 0
            elif seq == 1:
                if x - x_before < l + l_before:
                    del xls[-1]
                    xls.append(xls_input[i-1])
                    xl_before = xls[-1]
                    x_before = xl_before[0]
                    l_before = xl_before[1]
                    if x - x_before < l + l_before:
                        ans -= 1
                        seq = 1
                else:
                    xls.append(xl)
                    seq = 0              
        #print(xls)
    print(ans)

if __name__ == '__main__':
    main()

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
        if ranges[prv_idx][1] < ranges[idx][1]:
            prv_idx = idx
        idx += 1
    else:
        idx += 1
        prv_idx += 1
    if N - 1 < idx:
        break
print(N - removed_num)

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
    else:
        if ans[i][1]>ans[i+1][1]:
           j=i+1  
print(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 i+1+shift <= N-1:
            if robots[i] + robots_attr[robots[i]]['len'] - 1 >= robots[i+1+shift] - robots_attr[robots[i+1+shift]]['len'] + 1:
                robots_attr[robots[i+1+shift]]['eliminated'] = True
                eliminated += 1
                shift += 1
            else:
                break

print(N - eliminated)

Submission status: Wrong Answer

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

print(ans - 1)

Submission status: Wrong Answer

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

N = int(input())
robot_number = 0
arm_ranges = []
for n in range(N):
    [x, l] = [int(i) for i in input().split()]
    minimum = x - l
    maximum = x + l
    arm_ranges.append((maximum, minimum))

# 腕の届く端が小さいもの順にソート
arm_ranges_sorted = sorted(arm_ranges)

(ma, mi) = arm_ranges_sorted[0]
now_max = ma
robot_number += 1
for arm_range in arm_ranges_sorted[1:]:
    (ma, mi) = arm_range
    if mi >= now_max:
        robot_number += 1
        now_max = mi

print(robot_number)