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 = []
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, bisect_left

rr = []

s = []
sub = 0
ans = []
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

ans.append(N - sub)
sub = 0
s = []
for r in R[::-1]:
    sIdx = bisect_left(s, r[0][0])
    eIdx = bisect_left(s, r[0][1])

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

    else:
        sub += 1

ans.append(N - sub)

print(max(ans))

Submission status: Wrong Answer

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

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:
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 = []
now = np.zeros(n, dtype="float32")

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

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    XL = [tuple(map(int, input().split())) for _ in [0] * N]

    XL.sort()
    lr = []
    for x, l in XL:
        lr.append([x - l, x + l])
    g = [0] * N
    i, j = 0, 1
    for i in range(N - 1):
        for j in range(i + 1, N):
            if lr[i][1] > lr[j][0]:
                g[i] += 1
                g[j] += 1
            else:
                break

    if len(g) == 2 and g[0] == 1:
        print(1)
        return
    n = 0
    for i in g:
        if i > 1:
            n += 1
    print(N - n)


main()

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:
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     , []])
dat.sort(key = lambda x: x[1], reverse=True)
res = []
def do_count():
    for i in range(n):
        #print("i={0}".format(i))
        c = 0
        m = []
        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:
n = int(input())
List = [list(map(int,input().split())) for i in range(n)]
x = [[0] * 4 for i in range(n)]
for i in range(n):
  x[i][0]=List[i][0] - List[i][1]
  x[i][1]=List[i][0] + List[i][1]
  x[i][2]=x[i][1] - x[i][0]
  x[i][3]= i+1
#print(x)
min = x[0][0]
max = x[0][1]
len = x[0][2]
#print(min,max,len)
count = 0

for i in range(1,n):
  if min < x[i][0] < max or min < x[i][1] < max:
#    print("a")
    if len < x[i][2]:
      print(min,max,len)
      min = x[i][0]
      max = x[i][1]
      len = x[i][2]
      count += 1
    count += 1
print(n-count)

Submission status: Wrong Answer

Solution code:
n = int(input())
xl = []
for i in range(n):
    x1, l1 = map(int, input().split())
    xl.append([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][1] > xl[i][0] and xl[i][1] > xl[i + 1][0]:
        if xl[i - 1][1] > xl[i + 1][0]:
            ans -= 1
        else:
            xl[i] = copy.copy(xl[i - 1])
            ans -= 1
    elif xl[i - 1][1] > xl[i][0]:
        ans -= 1

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



print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())

robo_list = [[] for _ in range(N)]
next_list = [[] for _ in range(N)]


for i in range(N):
    X,L=map(int,input().split())
    for j in range(max(0,X-L),min(X+L,N)):
        for r in robo_list[j]:
            if r not in next_list[i]:
                next_list[i].append(r)

            if i not in next_list[r]:
                next_list[r].append(i)
        
        robo_list[j].append(i)

next_len=list(map(len,next_list))
nl=max(list(map(len,next_list)))

clear_N=0

while nl >= 1:
    r=next_len.index(max(next_len))
    for i in next_list[r]:
        next_list[i].remove(r)
    
    next_list[r].clear()
    clear_N+=1

    next_len=list(map(len,next_list))
    nl=max(next_len)


print(N-clear_N)

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

j = 0
for j in range(len(d)):
    i,l,r = d.pop(0)
    if j == 0:
        p_l = l
        p_r = r
        ans += 1
        #j += 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:

N = int(input())
list = [[0] * 2] * N

for i in range(N):
    list[i] = [int(e) for e in input().split()]
list.sort()

j = N
d = N - 1
i = 1
if N < 3:
    print(j)
else:
    while i == d:
        a = list[i - 1][0]
        b = list[i - 1][1]
        c = list[i][0]
        d = list[i][1]
        e = list[i + 1][0]
        f = list[i + 1][1]
        i = i + 1
        if ((a + b) > (c - d)) and ((c + d) > (e - f)):
            del(list[i])
            j = j - 1
            d = d - 1
            i = 1
    print(j)

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

	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

	cooo = 0
	care = 0
	for i in tt:
		if i == 1:
			if care == 0:
				cooo += 1
				care = 1
			else:
				#care = 0
				pass
		else:
			care = 0

	print(N-cooo)


if __name__ == "__main__":
	main()

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 == 1:
        ans -= 1
        flag = 0
    elif x[i][0]+x[i][1]>x[i+1][0]-x[i+1][1] and flag == 1:
        ans -= 1
        flag = 0
    elif x[i][0]+x[i][1]<=x[i+1][0] and flag == 0:
        flag = 1
    elif x[i][0]+x[i][1]<=x[i+1][0]-x[i+1][1] and flag == 0:
        flag = 1
print(ans)

Submission status: Wrong Answer

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

Range = []

for i in range(N):
  max_i = x[i] + l[i]
  min_i = x[i] - l[i]
  Range.append((min_i,max_i,x[i]))

Range = sorted(Range, key = lambda x:x[2])

#print(Range)
a = 1
b = 0
j = 1
#print(Range[0][1])

for i in range(N-1):
  #print(Range[a][0], end = ","),print(Range[a-1][1])
  if Range[a][0] >= Range[a-1][1]:
    a += 1
  else:
    Range.pop(a)

a = 1
"""
for i in range(N*2):
  #print(Range[i][0], end = ","),print(Range[i-j][1])
  if Range[a][1] <= Range[a-1][0]:
    a += 1
  else:
    Range.pop(i)
    j += 1
"""
#print(Range)
print(len(Range))

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):
            on_off = 1
            if flag[X[i]] != 1:
                del1_list.append(X[i])
            else:
                if flag[X[i+1]] == 1:
                    if R[X[i]] > R[-X[i+1]]:
                        del1_list.append(X[i])
                        on_off = 0
                del1 = 1
                if on_off:
                    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) > 1:
        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
            break
    if fl == 0:
        break
ans = len(X)
#if ans == 0:
#    ans = 1
print(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)

(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

print(robot_number)

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
hoji = 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  hoji > ude_mae:
        count += 1
        j += 1
    if ude_mae > ude_ushiro:
        count += 1
        hoji = ude_mae
        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:
n = int(input())
xl = []
ans = n
for i in range(n):
    x, l = map(int, input().split())
    xl.append([x - l + 1, x + l - 1])
x1 = 0
x2 = 1

while x2 < n:
    f = xl[x1][1]
    s = xl[x2][0]
    if s <= f:
        ans -= 1
        num1 = xl[x1][1] - xl[x1][0]
        num2 = xl[x2][1] - xl[x2][0]
        if num1 > num2:
            x1 += 1
            x2 += 1
        else:
            x2 += 1
    else:
        x1 += 1
        x2 += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
l.sort()
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:
# -*- 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()

	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

	cooo = 0
	care = 0
	for i in tt:
		if i == 1:
			if care == 0:
				cooo += 1
				care = 1
			else:
				care = 0
		else:
			care = 0

	print(N-cooo)


if __name__ == "__main__":
	main()

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, bisect_left

rr = []

s = []
sub = 0
ans = []
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

ans.append(N - sub)
sub = 0
s = []
for r in R:
    sIdx = bisect_left(s, r[0][0])
    eIdx = bisect_left(s, r[0][1])

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

    else:
        sub += 1

ans.append(N - sub)

print(max(ans))

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]
  keep = True
  if (x - l + 1 > l_max):
    ans+=1
    l_max = x + l -1
 
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+1 , bx , bx+bl-1 , x-l+1 , x , x+l-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())
li=[]
for i in range(n):
  tmpli=list(map(int, input().split()))
  li.append(tmpli)
li.sort()
for i in range(len(li)-1):
  if li[i][0]+li[i][1] > li[i+1][0]-li[i+1][1]:
    li[i+1][0] = li[i][0]
    li[i+1][1] = li[i][1]
    n -= 1
print(n)

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] or x[i][0]+x[i][1]>x[i+1][0]-x[i+1][1]) and flag == 1:
        ans -= 1
        flag = 0
    elif x[i][0]+x[i][1]<=x[i+1][0] and flag == 0:
        flag = 1
print(ans)

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


p_r = 10**10 + 1
p_l = -1 * (10**10 + 1)
ans = 0
flag = True

j = 0
while len(d) > 0:
    i,l,r = d.pop(0)
    if j == 0:
        p_l = l
        p_r = r
        ans += 1
        j += 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:
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[1][1] > data[2][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
    elif data[i][1] > data[i+1][0] and data[i][1] > data[i+2][0] and i < n:
        ans -= 1
        data[i][0] = 0
        data[i][1] = 0
    elif data[i-1][1] > data[i][0] and data[i-2][1] > data[i-1][0] and 2 < i:
        ans -= 1
        data[i][0] = 0
        data[i][1] = 0
      
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
X=[[0 for j in range(2)] for i in range(N)]
for i in range(N):
  X[i]=list(map(int,input().split()))
 
 
X.sort()
n=1
i=0
k=0
flag=0
if N==1:
  print(1)
else:
  while(1):
    #print(n,i,k)
    if X[i][0]+X[i][1]<=X[n-1][0]-X[n-1][1]:
      n=n-1
      flag=0
    else:
      flag2=-1
      for j in range(n-i):
        if X[i+j][0]+X[i+j][1]<=X[n][0]-X[n][1]:
          flag2=j
          break
      if flag2>=0:
        i=i+j+1
        if flag==0:
          k+=1
          flag=1
      elif X[i][0]+X[i][1]>X[n][0]-X[n][1]:
        n+=1
        flag=0
      else:
        i+=1
        if flag==0:
          k+=1
          flag=1
      
    if i>=N-1 or n>=N:
      break

  print(k+1)

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:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if x[mid] >= n:
        rr = mid
    else:
        ll = mid+1


n = onem()
a = []
b = []
for i in range(n):
    x,c = m()
    a.append([x-c-1,x+c-1])
    b.append([x-c-1,x+c-1])

a.sort(key = lambda x:(x[1]))
b.sort()
aa = []

for i in range(n):
    if not aa:
        aa.append(a[0])
        bbb = a[0][1]
    else:
        if bbb <= a[i][0]:
            aa.append(a[i])
            bbb = a[i][1]
        else:
            continue
print(aa)
print(len(aa))

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
    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:
# -*- 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)
        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:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if x[mid] >= n:
        rr = mid
    else:
        ll = mid+1


n = onem()
a = []
b = []
for i in range(n):
    x,c = m()
    a.append([x-c-1,x+c-1])
    b.append([x-c-1,x+c-1])

a.sort(key = lambda x:(x[1]))
b.sort()
aa = []

for i in range(n):
    if not aa:
        aa.append(a[0])
        bbb = a[0][1]
    else:
        if bbb <= a[i][0]:
            aa.append(a[i])
            bbb = a[0][1]
        else:
            continue
print(aa)
print(len(aa))

Submission status: Wrong Answer

Solution code:
n=int(input())
x=[]
for i in range(n):
    xi=list(map(int, input().split()))
    x.append(xi)
x_new=sorted(x) #これで、座標順にxとlを対応させて並べ替えできた
ans=n
if n==1:
    print(ans)
else:
    #xi-liより大、xi+liより小の範囲に何個のロボットがいるかをそれぞれ調べたい
    buf=[0]*n
    for i in range(n-1):
        c=0
        for j in range(i+1,n):
            if (x_new[i][0]+x_new[i][1])>=x_new[j][0]-x_new[j][1]:
                c+=1
            else:
                break
        buf[i]=c-1
    #両隣のかぶりの数と比較して、大きかったらそれを取り除く作業をする
    if n>2:
        for i in range(1,n-1):
            if buf[i]!=0 and buf[i-1]<=buf[i] and buf[i+1]<=buf[i]:
                ans-=1
        print(ans)
    elif buf[0]<buf[1] or buf[0]>buf[1]:
        ans-=1
        print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
xl = []
for i in range(n):
    x1, l1 = map(int, input().split())
    xl.append([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][1] > xl[i][0] and xl[i][1] > xl[i + 1][0]:
        xl[i] = copy.copy(xl[i - 1])
        ans -= 1
    elif xl[i - 1][1] > xl[i][0]:
        xl[i] = copy.copy(xl[i - 1])
        ans -= 1

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



print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N=int(input())
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 right-(XLs[i+1][0]+XLs[i+1][1])>0:
        right=XLs[i+1][0]+XLs[i+1][1]
    elif XLs[i+1][0]-XLs[i+1][1]-right>=0:
        ans+=1
        right=XLs[i+1][0]-XLs[i+1][1]
print(ans)