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

list_ = list()

for i in range(N):
  X,L = map(int,input().split())
  max_ = min(10**9,X+L)
  min_ = max(0,X-L+1)
  list_.append((X,min_,max_))
list_.sort()

d = 0
nowmax = -1
nowmin = -1

for x, min_, max_ in list_:
  if nowmax > min_:
    d += 1
    if nowmin >= min_:
      pass
    elif nowmax <= max_:
      pass
    else:
      nowmin = min_
      nowmax = max_
  else:
    nowmin = min_
    nowmax = max_
  
print(N-d)

Submission status: Wrong Answer

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

    X_L = tuple(tuple(int(j) for j in input().split()) for i in range(N))
    ranges = tuple((x - l, x + l) for x, l in X_L)
    # sorted_X_L = sorted(X_L, key=lambda x: x[0])

    # dupl = [len([]) for i in range(N)]

    # sorted_ranges = sorted(ranges, key=lambda x: x[0])
    #
    # x_max = - 1e9
    # x_min = 2e9
    #
    # allowed = []
    #
    # for i in range(N):
    #     i_min = sorted_X_L[i][0] - sorted_X_L[i][1]
    #     i_max = sorted_X_L[i][0] + sorted_X_L[i][1]
    #
    #     if i_min >= x_max or i_max <= i_min:
    #         allowed.append(sorted_X_L[i])
    #         x_max = max(x_max, i_max)
    #         x_min = min(x_min, i_min)
    #
    # print(len(allowed))

    dup = duplicate_matrix(ranges)
    print(1)


def calc_duplicates(items):
    result = [0 for i in range(len(items))]

    for i in range(len(items)):

        for j in range(len(items)):
            if is_duplicates(items[i], items[j]):
                result[i] += 1
    return result


def duplicate_matrix(items):
    result = [[0 for j in range(len(items))] for i in range(len(items))]

    for i in range(len(items)):
        for j in range(len(items)):
            if is_duplicates(items[i], items[j]):
                result[i][j] = 1
    return result


def is_duplicates(range1, range2):
    return range1[1] > range2[0] or range1[0] < range2[1]


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
robots = []
for k in range(n):
  robots.append(list(map(int, input().split())))
  
robots.sort()
res = 0
skip_flag = False
for i in range(n):
  if skip_flag:
    slip_flag = False
    continue
  if i == n - 1:
    break
  a_robot = robots[i]
  b_robot = robots[i+1]
  ax = a_robot[0]
  al = a_robot[1]
  bx = b_robot[0]
  bl = b_robot[1]
  #error1 = False
  if (al + bl) <= (bx - ax):
    continue
  res += 1
  if i == n - 2:
    continue
  c_robot = robots[i+2]
  cx = c_robot[0]
  cl = c_robot[1]
  if (bl + cl) <= (cx - bx):
    continue
  skip_flag = True
  
print(n-res)

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
xl.sort()
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())

wk =[]
for i in range(n):
    wk.append(list(map(int,input().split())))
xl = sorted(wk, key=lambda x:x[0])

xx = []
ll = []
cnt = 0

for i in range(n):
    x,l = xl[i][0],xl[i][1]

    if i == 0 or xx[cnt-1] + ll[cnt-1] -1 <  x - l +1:
        xx.append(x)
        ll.append(l)
        cnt +=1

print(len(xx))

Submission status: Wrong Answer

Solution code:
N = int(input())
list_1 = [list(map(int,input().split())) for i in range(N)]
#print(list_1)
list_1.sort()
#print(list_1)
for i in range(N-1):
    if list_1[i][0] == list_1[i+1][0]:
        if list_1[i][1] >= list_1[i+1][1]:
            list_1[i] = [0,0]
        else:
            list_1[i+1] = [0,0]
    else:
        None
list_1.sort()
#print(list_1)
result = 0
a = 0
if list_1[0][1] != 0:
    result += 1
    a = list_1[0][0] + list_1[0][1]
try:
    for j in range(len(list_1)):
        if list_1[j][0] == list_1[j][1] and list_1[j][0] == 0 and list_1[j][0] == list_1[j + 1][0]:
            None
        elif list_1[j][0] == list_1[j][1] and list_1[j][0] == 0 and list_1[j][0] != list_1[j + 1][0]:
            result += 1
            a = list_1[j + 1][0] + list_1[j + 1][1]
            #print("2716")
        elif a <= list_1[j][0] - list_1[j][1]:
            #print("!!!!!!!")
            result += 1
            a = list_1[j][0] - list_1[j][1]
except:
    None
print(result)

Submission status: Wrong Answer

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

N = int(input())
robot_number = N
XL = {}
for n in range(N):
    [x, l] = [int(i) for i in input().split()]
    XL[x] = l

#available_positions = {}
#for i in range(-1000, 1000):
#    available_positions[i] = 0
used_area = []

# 腕の長さでsort
XL_sorted = sorted(XL.items(), key=lambda x:x[1])

# 腕の長さが短いものから見ていって、かぶっていたら削除
for (x, l) in XL_sorted:

    # このロボットの腕の範囲に既にロボットがいるか確認
    flag = False
    #position = x - l + 0
    #while position < x + l - 1:
    #    if available_positions[position] != 0:
    #        flag = True
    #        break
    #    position += 1
    minimum = x-l
    maximum = x+l
    for (mi, ma) in used_area:
        if minimum < ma and maximum > mi:
            flag = True
            break

    if flag is True:
        robot_number -= 1
        continue

    # このロボットの範囲をメモ
    #position = x - l + 0
    #while position < x + l - 1:
    #    available_positions[position] = 1
    #    position += 1
    used_area.append((x-l, x+l))


print(robot_number)

Submission status: Wrong Answer

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
xl = [LI() for _ in range(n)]
lst = []
for x,l in xl:
    lst.append((x-l,x+l))
lst = sorted(lst,key = lambda x:(x[1],x[0]))
ans = 0
i = 0
while i < n:
    (l,r) = lst[i]
    j = i+1
    while j < n:
        (l1,r1) = lst[j]
        if l < l1 < r or l1 < l < r1:
            ans += 1
        else:
            break
        j += 1
    i = j
print(n-ans)

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:
    l -= 1
    ll = x - l
    if ll <= rl:
        tikan += 1
        rl = min(rl, x + l)
    else:
        ans += 1
        rl = x + l
print(N - tikan)

Submission status: Wrong Answer

Solution code:
#2
n=int(input())
XL=dict()
ans=n
last=0
for i in range(n):
    x,l=map(int,input().split())
    if last<x:
        last=x
    XL[x]=l
XL=sorted(XL.items())
s=list(XL)
for i in range(n-1):
    if (s[i+1][0]-s[i][0])<(s[i+1][1]+s[i][1]):
        ans-=1

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import math

def findTwoDup(positions, arms, N):
    indices = []
    for i in range(1, N-1):
        left_distance_between = abs(positions[i] - positions[i-1])
        right_distance_between = abs(positions[i] - positions[i+1])
        left_touched = left_distance_between < (arms[i] + arms[i-1])
        right_touched = right_distance_between < (arms[i] + arms[i+1])
        if left_touched and right_touched:
            indices.append(int(i))
    return indices

def findDup(positions, arms, N):
    indices = []
    for i in range(N-1):
        right_distance_between = abs(positions[i] - positions[i+1])
        right_touched = right_distance_between < (arms[i] + arms[i+1])
        if right_touched:
            indices.append(int(i))
    return indices



positions = []
arms = []
N = int(input())
for i in range(N):
    a, b = (int(n) for n in input().split())
    positions.append(a)
    arms.append(b)
two_dup_indices = findTwoDup(positions, arms, N)
while len(two_dup_indices) != 0:
    removed_index = two_dup_indices.pop(-1)
    positions.pop(removed_index)
    arms.pop(removed_index)
dup_indices = findDup(positions, arms, len(arms))
while len(dup_indices) != 0:
    removed_index = dup_indices.pop(-1)
    positions.pop(removed_index)
    arms.pop(removed_index)
print(len(arms))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
def main():
    N = int(input())
    robo = []

    for _ in range(N):
        x, l = map(int, input().split())
        l = l-1
        robo.append((x+l, x-l))

    robo.sort()
    #print(robo)
    ans = 0
    t = -100000000000000000000000000000000000000000000000000000000
    for i in range(N):
        if t < robo[i][1]:
            ans += 1
            t = robo[i][0]

    print(ans)




    return 0

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
temp = [input() for _ in range(n)]
x = [0]*n
l = [0]*n
for i in range(n):
  x[i],l[i] = map(int, temp[i].split())
temp2 = zip(x,l)
x,l = zip(*sorted(temp2))
x = list(x)
l = list(l)
result=n
for j in range(n-1):
  if x[j]==0: continue
  if x[j]+l[j]>x[j+1]-l[j+1]:
    if j<(n-2) :
      if x[j+1]+l[j+1]>x[j+2]-l[j+2]:
        result-=1
        x[j+1]=0
        l[j+1]=0
      else:
        result-=1
        x[j]=0
        l[j]=0
    else:
      result-=1
      x[j]=0
      l[j]=0
print(result)

Submission status: Wrong Answer

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

X = 0
N = 0
co = 0
ans = 0


for i in range(len(lis)):
    h = []
    h = lis[i]
    X = h[0]
    N = h[1]    
    if i == 0:
        co = X+N
        ans += 1
    else:
        if co - X < 0:
            co = X+N
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

list_ = list()

for i in range(N):
  X,L = map(int,input().split())
  max_ = min(10**9,X+L)
  min_ = max(0,X-L+1)
  list_.append((X,min_,max_))
list_.sort()

d = 0
nowmax = -1
nowmin = -1

for x, min_, max_ in list_:
  if nowmax >= min_:
    d += 1
    if nowmin >= min_:
      pass
    elif nowmax <= max_:
      pass
    else:
      nowmin = min_
      nowmax = max_
  else:
    nowmin = min_
    nowmax = max_
  
print(N-d)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = [0]*N
L = [0]*N
d = {}
max = 0
del_count = 0
first = 0
for i in range(N):

  x,l= map(int,list(input().split()))
  if i == 0:
    first = x
  d[x] = l
s = sorted(d.items(), key=lambda x:x[0])
new_list = sorted(X)
for x,l in s:
  if first == x:
    max = x + l
  elif max > x - l:
    del_count +=1
  else:
    max = x + l
print(N-del_count)

Submission status: Wrong Answer

Solution code:
# 2020/01/18
# キーエンス プログラミング コンテスト 2020 - B

from operator import itemgetter

# Input
n = int(input())

in_list = list()

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

in_list.sort(key=itemgetter(0))

# Calc
wkx_a = in_list[0][0]
wkl_a = in_list[0][1]
dp = [0] * n
dp[0] = 1
wkx_b = 10 ** 10
wkl_b = 10 ** 10

for i in range(1, n):
    x = in_list[i][0]
    l = in_list[i][1]
    if wkx_a + wkl_a + l <= x:
        wkx_b = wkx_a
        wkl_b = wkl_a
        wkx_a = x
        wkl_a = l
        dp[i] = dp[i-1] + 1
    else:
        if wkx_b + wkl_b + l <= x:
            wkx_a = x
            wkl_a = l
            dp[i] = dp[i-2] + 1
            wkx_b = wkx_a
            wkl_b = wkl_a
        else:
            dp[i] = dp[i-1]

ans = max(dp[n-1], dp[n-2])

# Output
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
ans = 0
x = [0] * n
for i in range(n):
    x[i] = tuple([int(x) for x in input().strip().split()])

x.sort()
pre = -float('inf')

for xx in x:
    if pre > xx[0] - xx[1]:
        pre = min(pre, xx[0]+xx[1])
        #print(xx, pre)
        continue
    
    ans += 1
    pre = xx[0] + xx[1]
    #print(xx, pre)

x.reverse()
pre = float('inf')
ans2 = 0
for xx in x:
    if pre < xx[0] + xx[1]:
        pre = max(pre, xx[0]+xx[1])
        #print(xx, pre)
        continue
    
    ans2 += 1
    pre = xx[0] - xx[1]
    #print(xx, pre)

print(max(ans, ans2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
x={}
y={}
for i in range(N):
    x[i],y[i] = map(int, input().split())

Red = N

for i in range(N-1):
    before = x[i] + y[i]
    after  = x[i+1] + y[i+1]

    if (after < before):
        Red -= 1

print(Red)

Submission status: Wrong Answer

Solution code:
N = int(input())
XL = []
flag = [0]*N
for i in range(N):
	xl = list(map(int,input().split()))
	XL.append(xl)
XL.sort()
for i in range(N-1):
	if(flag[i] == 0):
		if(XL[i][0]+XL[i][1]>=XL[i+1][0]):
			flag[i+1]+=1
sum = 0
for i in range(N):
	sum+=flag[i]
print(N-sum)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import bisect
N=int(input())
d=[0]*N
s=[0]*N
for i in range(N):
    a,b=map(int,input().split())
    s[i]=a-b
    d[i]=a+b
d.sort()
s.sort()
cnt=[]
#print(d)
#print(s)
for i in range(N):
    cnt.append(N-bisect.bisect_left(s,d[i]))
    #print(cnt)
print(cnt[0]+1)

Submission status: Wrong Answer

Solution code:
n = int(input())
rx = {}

minrx = 10 ** 10
minrx_idx = -1
for i in range(n):
    xx, ll = map(int, input().split(' '))
    rx[xx - ll] = (xx - ll, xx + ll)

rxs = sorted(rx.items(), key=lambda x:x[0])

rxs2 = [i[1] for i in rxs]

now_idx = 0
cnt1 = 1
for i, x in enumerate(rxs2):
    if now_idx == i:
        continue
    if rxs2[now_idx][1] > rxs2[i][0]:
        continue
    now_idx += 1
    cnt1 += 1

rxs3 = rxs2[1:]

now_idx = 0
cnt2 = 1
for i, x in enumerate(rxs3):
    if now_idx == i:
        continue
    if rxs3[now_idx][1] > rxs3[i][0]:
        continue
    now_idx += 1
    cnt2 += 1

print(max(cnt1, cnt2))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
n = int(input())
ans = n
A = []
for i in range(n):
    x, l = [int(i) for i in input().split()]
    A.append([x-l+1, x+l-1])
A = sorted(A, key = itemgetter(0))
cur_end = A[0][1]
for i in range(n-1):
    if cur_end >= A[i+1][0]:
        ans -= 1
        cur_end = min(A[i+1][1], cur_end)
    else:
        cur_end = A[i+1][1]
print(ans)

Submission status: Wrong Answer

Solution code:
def bubble_sort(X, L):
    change = True
    while change:
        change = False
        for i in range(len(X) - 1):
            if X[i] > X[i + 1]:
                X[i], X[i + 1] = X[i + 1], X[i]
                L[i], L[i + 1] = L[i + 1], L[i]
                change = True
    return X, L


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

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

X, L = bubble_sort(X, L)

i = 1
out = []
for x in X:
    right = L[i-1] + x
    for j in range(N):
        if((i+j) >= N):
            break

        if(right <= (X[j+i] - L[j+i])):
            pass
        else:
            out.append(j+i)
    i += 1

print(N - len(set(out)))

Submission status: Wrong Answer

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
xl = [LI() for _ in range(n)]
lst = []
for x,l in xl:
    lst.append((x-l,x+l))
lst.sort(key = itemgetter(1))
ans = 0
i = 0
while i < n:
    (l,r) = lst[i]
    j = i+1
    while j < n:
        (l1,r1) = lst[j]
        if l < l1 < r or l1 < l < r1:
            ans += 1
        else:
            break
        j += 1
    i = j+1
print(n-ans)

Submission status: Wrong Answer

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

s = 0

for i in range(0, len(X)-1, 1):
  a = X[i]
  min = a[0] - a[1]
  max = a[0] + a[1]
  for j in range(i+1, len(X), 1):
    b = X[j]
    b_min = b[0] - b[1]
    b_max = b[0] + b[1]
    if min <= b_max and max >= b_min:
      s += 1
    

print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())
XL = [list(map(int,input().split())) for _ in range(N)]
XL.sort()
r_l = []
number = [0]*N
S = 0
for n in range(N):
  xl = XL[n]
  x = xl[0]
  l = xl[1]
  r_l.append([x-l,x+l])
  
i = 1
for i in range(0,N-1):
  j = i+1
  while True:
    if j>N-1:
      break
    if r_l[i][1]>r_l[j][0]:
      number[i] += 1
      number[j] += 1
      j += 1
      S+=2
    else:
      break

ans = N
S //= 2
number.sort(reverse = True)
for i in number:
  if S==0:
    break
  S -= i
  ans -= 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())

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

ans=1
before=sum(L[0])
for i in range(1,n):
    if before<=(L[i][0]-L[i][1]):
        before=sum(L[i])
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input().strip())
xl = []
for i in range(n):
    xl.append(list(map(int, input().split())))
xl.sort()
if n == 1:
    print(0)
    exit()
if n == 2:
    if (xl[1][0] - xl[1][1]) < (xl[0][0] + xl[0][1]):
        print(1)
        exit()
    else:
        print(0)
        exit()
ans = 0
while 3 <= len(xl):
    reps = [0] * len(xl)
    for i in range(len(xl) - 2):
        cnt = 0
        if (xl[i + 1][0] - xl[i + 1][1]) < (xl[i][0] + xl[i][1]):
            cnt += 1
        if (xl[i + 2][0] - xl[i + 2][1]) < (xl[i + 1][0] + xl[i + 1][1]):
            cnt += 1
        reps[i + 1] = cnt
    tmp = []
    add = 0
    for i in range(len(xl)):
        if reps[i] != 2:
            tmp.append(xl[i])
        else:
            add += 1
    if add == 0:
        break
    else:
        ans += add
    xl = tmp

reps = [0] * len(xl)
for i in range(len(xl) - 1):
    if (xl[i + 1][0] - xl[i + 1][1]) < (xl[i][0] + xl[i][1]):
        reps[i + 1] = 1
print(n - (ans + (reps.count(1) // 2)))

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect_left as bl
input = sys.stdin.readline
N = int(input())
a = []
p = []
res = 0
for _ in range(N):
  x, l = map(int, input().split())
  a.append((x - l + 1, x + l - 1))
  p.append(x - l + 1)
p.sort()
a.sort(key = lambda x: x[0])
#print(a)
#print(p)
for i in range(N):
  r = bl(p, a[i][1])
  #print(a[i], r, i)
  res += max(r - i - 1, 0)
print(N - res)

Submission status: Wrong Answer

Solution code:
n = int(input())

E = []
for i in range(n):
    x, l = map(int, input().split(' '))
    s = max(x - l, 0)
    g = min(x + l, 10**9)
    E.append((s, g))
E = sorted(E)

g = -1
count = 0
for e in E:
    s = e[0]
    if s < g:
        continue
    else:
        g = e[1]
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())

line_min = 1000000000
line_max = -1000000000

ans = 0
line  = []

for i in range(n):
  x, l = map(int, input().split())
  keep = True
  if (x - l + 1 <= line_min) and (x + l - 1 >= line_min):
    keep = False
  elif (x - l + 1 <= line_max) and (x + l - 1 >= line_max):
    keep = False
  else:
    for j in range (x-l+1, x+l):
      if j in line:
        keep = False

  print(line_min, line_max, keep)
  if keep == True:
    line_min = x - l + 1
    line_max = x + l - 1
    for k in range (x-l+1, x+l):
      line.append(k)
    ans += 1

print(ans)

Submission status: Wrong Answer

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

N = int(input())
robot_number = N
XL = {}
for n in range(N):
    [x, l] = [int(i) for i in input().split()]
    XL[x] = l

#available_positions = {}
#for i in range(-1000, 1000):
#    available_positions[i] = 0
used_area = []

# 腕の長さでsort
XL_sorted = sorted(XL.items(), key=lambda x:x[1])

# 腕の長さが短いものから見ていって、かぶっていたら削除
for (x, l) in XL_sorted:

    # このロボットの腕の範囲に既にロボットがいるか確認
    flag = False
    #position = x - l + 0
    #while position < x + l - 1:
    #    if available_positions[position] != 0:
    #        flag = True
    #        break
    #    position += 1
    minimum = x-l+1
    maximum = x+l-1
    for (mi, ma) in used_area:
        if minimum < ma and maximum > mi:
            flag = True
            break

    if flag is True:
        robot_number -= 1
        continue

    # このロボットの範囲をメモ
    #position = x - l + 0
    #while position < x + l - 1:
    #    available_positions[position] = 1
    #    position += 1
    used_area.append((x-l+1, x+l-1))


print(robot_number)

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

    xls = []
    ans = N
    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 x - x_before < l + l_before:
                ans -= 1
            else:
                xls.append(xl)

    xls2 = []
    ans2 = N
    for i in range(N):
        xl = xls_input[N-i-1]
        if i == 0:
            xls2.append(xl)
        else:
            xl_before = xls2[-1]
            x_before = xl_before[0]
            l_before = xl_before[1]
            x = xl[0]
            l = xl[1]
            if abs(x - x_before) < l + l_before:
                ans2 -= 1
            else:
                xls2.append(xl)
    
    if ans >= ans2:
        print(ans)
    else:
        print(ans2)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
l_i = []
for i in range(n):
    l_i.append(tuple(map(int,input().split())))
l = copy.deepcopy(l_i)
l = sorted(l)
ans = n
for i in range(n-1):
    L = l[i][0]+l[i][1]
    R = l[i+1][0]-l[i+1][1]
    if L > R:
        ans -= 1
        l[i+1] = l[i]

l2 = copy.deepcopy(l_i)
l2 = sorted(l2,reverse=True)
ans2 = n
for i in range(n-1):
    L = l2[i+1][0]+l2[i+1][1]
    R = l2[i][0]-l2[i][1]
    if L > R:
        ans2 -= 1
        l2[i+1] = l2[i]
print(max(ans,ans2))

Submission status: Wrong Answer

Solution code:
import math
def main():
    N = int(input())
    robo = []

    for _ in range(N):
        x, l = map(int, input().split())
        l = l-1
        robo.append((x+l, x-l))

    robo = sorted(robo, key=lambda x: x[0])
    #print(robo)
    ans = 0
    t = -100000000000000000000000000000000000000000000000000000000
    for i in range(N):
        if t <= robo[i][1]:
            ans += 1
            t = robo[i][0]

    print(ans)




    return 0

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

N = int(input())

robots = []

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

robots.sort()
new = []
for robot in robots:

    if len(new) == 0:
        new.append(robot)
    
    if (new[-1][0] + new[-1][1]) <= (robot[0] - robot[1]):
        new.append(robot)

    else:

        if new[-1][1] < robot[1]:
            pass

        else:
            new.pop()
            new.append(robot)

print(len(new))

Submission status: Wrong Answer

Solution code:
N = int(input())
XL = []
for i in range(N):
    xl = [int(i) for i in  input().split()]
    xl[1] -= 1
    XL.append(xl)
XL.sort()
rm = 0
prev_arm = 0
for i in range(1, N):
    if XL[i][0] - XL[i][1] <= XL[prev_arm][0] + XL[prev_arm][1]:
        rm += 1
    else:
        prev_arm = i
print(N - rm)

Submission status: Wrong Answer

Solution code:
N = int(input())

robot = [[0 for i in range(3)] for j in range(N)]

for k in range(N):
    x, l = [int(l) for l in input().split()]
    robot[k][0] = x
    robot[k][1] = x - l
    robot[k][2] = x + l

robot = sorted(robot)

#print(robot)

count = 0

for m in range(N-1):
    try:
        if (robot[m][2] > robot[m+1][1]):
            del robot[m+1]
            N = N-1
        else:
            continue
    except:
        break

print(len(robot))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

Submission status: Wrong Answer

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

x_l.sort()
if N<3:
  for i in range(1,N):
    if (x_l[i-1][0] + x_l[i-1][1]) > (x_l[i][0] - x_l[i][1]):
      del x_l[i]
    print(len(x_l))
#else:
#  for i in range(1,N-1):
#    if (x_l[i-1][0] + x_l[i-1][1]) > (x_l[i][0] - x_l[i][1]):
#      del x_l[i]

#  print(len(x_l))

Submission status: Wrong Answer

Solution code:
def resolve():
    import sys
    readline = sys.stdin.readline
    N = int(readline())
    l = [list(map(int, input().split())) for _ in range(N)]
    l.sort(key=lambda x: x[0])

    count = 0
    for i in range(N-1):
        j = i + 1
        while j < N and l[i][0]+l[i][1] > l[j][0] - l[j][1]:
            l[j][0] = -1 * 10 ** 9
            l[j][1] = 0
            j += 1
            N -= 1
    print(N)
resolve()

Submission status: Wrong Answer

Solution code:
N = int(input())
XL = []
for _ in range(N):
    x, l = map(int, input().split())
    XL.append([x, l])
XL.sort()
m = 10 ** 9
k = 0
for i in range(N):
    if m >= XL[i][1]:
        m = XL[i][1]
        k = i
ans = 1
prev = XL[k]
for i in range(k+1, N):
    x, l = XL[i]
    if x - l >= prev[0] + prev[1]:
        ans += 1
        prev = [x, l]
prev = XL[k]
for i in list(range(0, k))[::-1]:
    x, l = XL[i]
    if x + l <= prev[0] - prev[1]:
        ans += 1
        prev = [x, l]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

xl = []

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

for i in range(N):
    itv.append([xl[i][0]+xl[i][1]-1,xl[i][0]-xl[i][1]+1])
itv.sort()

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

Submission status: Wrong Answer

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

list = []

for i in range(0, len(X)-1, 1):
  a = X[i]
  min = a[0] - a[1]
  max = a[0] + a[1]
  for j in range(i+1, len(X), 1):
    b = X[j]
    b_min = b[0] - b[1]
    b_max = b[0] + b[1]
    if min <= b_max and max >= b_min:
      list.append(a)
    

print(int(len(list)))

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

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

for i in range(N):
    if robots[i][-1]:
        continue
    if i != N-1:
        if robots[i][0] + robots[i][1] - 1 >= robots[i+1][0] - robots[i+1][1] + 1:
            if robots[i][1] > robots[i+1][1]:
                robots[i][-1] = True
            else:
                robots[i+1][-1] = True

ans = 0
for robot in robots:
    if not robot[-1]:
        ans += 1

print(ans)

Submission status: Wrong Answer

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

d.sort(key=lambda x:x[1],reverse=False)

p = 10**9 + 1
ans = 0
while len(d) > 0:
    i,l,r = d.pop(-1)
    #print(i,l,r,p)
    if r >= p:
        ans += 1
    else:
        p = l
    #print(d)
print(n-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
flag = True

while(1):
    flag = True
    
    for k in range(n-1):
      if (x[k+1][0] - x[k][0]) < x[k][1] + x[k+1][1] and x[k+1][0]>0 and x[k][0]>0:
        remove +=1
        x[k+1][0] = -1
       	flag =False
        k -=1

    if flag == True:
        break
    
print (n -remove)

Submission status: Wrong Answer

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
xl = [LI() for _ in range(n)]
lst = []
for x,l in xl:
    lst.append((x-l,x+l))
lst.sort(key = itemgetter(1))
ans = 0
i = 0
while i < n:
    (l,r) = lst[i]
    j = i+1
    while j < n:
        (l1,r1) = lst[j]
        if l < l1 < r or l1 < l < r1:
            ans += 1
        else:
            break
        j += 1
    i = j
print(n-ans)