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: Runtime Error

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

if X[-1]-L[-1]<X[-2]+L[-2]:
    ans+=1
print(N-ans)

Submission status: Runtime Error

Solution code:
from operator import itemgetter

N = int(input())
input_list = []
lobot_list = []
tmp_lobot_list = []
for i in range(N):
    tmp = input()
    tmp_list = tmp.split()
    tmp_lobot_list.append(tmp_list)
    
sorted(tmp_lobot_list,key=itemgetter(0))



for i in range(N):
    tmp = tmp_lobot_list[i]
    tmp_list = tmp.split()
    tmp_lobot_list.append(tmp_list)


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

Submission status: Runtime Error

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
    i = 0
    while i <= N - 1:
        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]
                    i -= 1
                    seq = 0
                else:
                    xls.append(xl)
                    seq = 0              
        i += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from operator import itemgetter

N = int(input())
input_list = []
lobot_list = []
tmp_lobot_list = []
for i in range(N):
    tmp = input()
    tmp_list = tmp.split()
    tmp_lobot_list.append(tmp_list)
    
sorted(tmp_lobot_list,key=itemgetter(0))



for i in range(N):
    tmp = tmp_lobot_list
    tmp_list = tmp.split()
    tmp_lobot_list.append(tmp_list)


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

Submission status: Runtime Error

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: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())

data = np.zeros((n, 2))
for i in range(n):
  x_tmp, l_tmp = map(int,input().split(' '))
  data[i] = x_tmp, l_tmp

data.sort(axis=0)

if n == 0:
  nRem = 0
elif n == 1:
  nRem = 0
else:
  cnt=0
  for inf_loop in range(n):
    nLoop = n-1-cnt
    for i in range(nLoop):
        a = data[i,0] + data[i,1]
        b = data[i+1,0] - data[i+1,1]
        
        if a > b:
          if i == 0:
            del data[i+1]
          else:
            del data[i]
            
          cnt += 1
          break

    if i == nLoop-1:
      break
  nRem = n - cnt
  
print(nRem)

Submission status: Runtime Error

Solution code:
N = int(input())
A_list = [input().split() for _ in range(N)]
 
ans = []
before_count = 0
 
 
def has_duplicates(seq):
    return len(seq) != len(set(seq))
 
 
def open(list):
    retval = range(int(list[0]) - int(list[1]), int(list[0]) + int(list[1]))
    return retval
 
 
for i in range(2 ** len(A_list)):
    ans = []
    count = 0
    for j in range(len(A_list)):
        if (i >> j) & 1:
            count += 1  # 使用している個数
            ans += open(A_list[len(A_list) - 1 - j])
 
    if not has_duplicates(ans):
        if count > before_count:
            before_count = count
 
print(before_count)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())

data = np.zeros((n, 2))
for i in range(n):
  x_tmp, l_tmp = map(int,input().split(' '))
  data[i] = x_tmp, l_tmp

data.sort(axis=0)

if n == 0:
  nRem = 0
elif n == 1:
  nRem = 0
else:
  cnt=0
  for inf_loop in range(n):
    nLoop = n-1-cnt
    for i in range(nLoop):
        a = data[i,0] + data[i,1]
        b = data[i+1,0] - data[i+1,1]
        print(a,b)
        
        if a > b:
          if i == 0:
            del data[i+1]
          else:
            del data[i]
            
          cnt += 1
          break

    if i == nLoop-1:
      break
  nRem = n - cnt
  
print(nRem)

Submission status: Runtime Error

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()
idx = []
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]):
      idx.append(i)
else:
  for i in range(1,N-2):
    if (x_l[i][0] + x_l[i][1]) > (x_l[i+1][0] - x_l[i+1][1]):
      idx.append(i)

for i in idx:
  del x_l[i]

print(len(x_l))

Submission status: Runtime Error

Solution code:
import sys
import itertools
from copy import copy

def swap(i,P,Q):
    Q[i+1],Q[i],P[i+1],P[i]=P[i],P[i+1],Q[i],Q[i+1]
    return P,Q

def judge(P):
    for i in range(len(P)-1):
        if P[i]>P[i+1]:
            return False
    else:
        return True

N=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
flag=False
if judge(A):
    print(0)
    sys.exit()
for l in itertools.permutations(range(0,N-1)):
    if flag:
        break
    T=copy(A)
    Y=copy(B)
    count = 0
    for i in l:
        T,Y=swap(i,T,Y)
        count += 1
        if judge(T):
            ans = l
            flag=True
            print(count)
            break
else:
    print(-1)
    sys.exit()
#T=copy(A)
#Y=copy(B)
#print(T,Y)
#for i in ans:
#    T,Y=swap(i,T,Y)
#    print(T,Y)

Submission status: Runtime Error

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()
idx = []
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]):
      idx.append(i)
else:
  for i in range(1,N-2):
    if (x_l[i-1][0] + x_l[i-1][1]) > (x_l[i][0] - x_l[i][1]):
      idx.append(i)

for i in idx:
  del x_l[i]

print(len(x_l))

Submission status: Runtime Error

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
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: Runtime Error

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

rangeList = []
for element in XLList:
    Xi = element[0]
    Li = element[1]
    rangeList.append(range(Xi-Li, Xi+Li))

tmpList = []
for i in range(N):
    continueFlg = True

    tmpElement = rangeList[i]
    if i != N - 1:
        nextElement = rangeList[i+1]

    minTmp = min(tmpElement)
    maxTmp = max(tmpElement)
    minNext = min(nextElement)
    maxNext = max(nextElement)
    if minNext < minTmp < maxNext or \
            minNext < maxTmp < maxNext or \
            minTmp < minNext < maxTmp or \
            minTmp < maxNext < maxTmp:
        continueFlg = False

    if continueFlg:
        tmpList.append(rangeList[i])

print(len(tmpList))

Submission status: Runtime Error

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()
idx = []
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]):
      idx.append(i)
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]):
      idx.append(i)

for i in idx:
  del x_l[i]

print(len(x_l))

Submission status: Runtime Error

Solution code:
# coding: utf-8
import collections


def main():
    n = int(input())
    inputs = [input().split() for i in range(n)]
    inputs_list = []
    for i in inputs:
        if int(i[0]) - int(i[1]) < 0:
            inputs_list += (range(0, int(i[0]) + int(i[1])))
        else:
            inputs_list += (range(int(i[0]) - int(i[1]), int(i[0]) + int(i[1])))
    c = collections.Counter(inputs_list)
    print(n - (c.most_common()[0][1] - 1))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n=int(input())
xl=[]
for i in range(n):
    data=list(map(int,input().split()))
    xl.append(data)
xl.sort(key=lambda x:x[0])
nx=[]
nl=[]
if  xl[0][0]+xl[0][1]<xl[1][0]+xl[1][1]:
    nx.append(xl[0][0])
    nl.append(xl[0][1])
if n>2:
    for i in range(1,n-1):
        if xl[i][0]-xl[i][1]>xl[i-1][0]-xl[i-1][1] and xl[i][0]+xl[i][1]<xl[i+1][0]+xl[i+1][1]:
            nx.append(xl[i][0])
            nl.append(xl[i][1])
if n>1:
    if xl[n-1][0]-xl[n-1][1]>xl[n-2][0]-xl[n-2][1]:
        nx.append(xl[n-1][0])
        nl.append(xl[n-1][1])
y=nx[0]-nl[0]
cnt=0
for i in range(len(nx)):
    if y<=nx[i]-nl[i]:
        y=nx[i]+nl[i]
        cnt+=1
print(cnt)

Submission status: Runtime Error

Solution code:
def count_conf(a,thresh):
  targets = []
  count = 0
  t=0
  for i in a:
    if i[2] < thresh:
      count += 1
      targets.append(t)
    if i[2] > thresh:
      break
    t += 1
  return count

n= int(raw_input())
d = []
for i in range(n):

	r, l= raw_input().split(" ")
	left_most = int(r) - int(l)
	d.append([int(r),int(l),left_most])
    
s = []
s = sorted(d, key=lambda tup: tup[2])
t = 0
ss = []
for i in s:
  x_current = i[0]
  l_current = i[1]
  reach = x_current + l_current
  c = count_conf(s[t+1:],reach)
  ss.append([i[0],i[1],i[2],c])
  t += 1
  
#by_most_conflicting = sorted(ss, key=lambda tup: tup[3]).reverse()

def conf_exist(a):
  for i in a:
    if a[3] != 0:
      return True
  return False


t=0
popped = 0
for i in ss:
  x_current = s[t][0]
  x_next = s[t+1][0]
  l_current = s[t][1]
  l_next = s[t+1][1]
  
  if (x_current + l_current) > (x_next - l_next):
    # current interserts with next
    # pop next
    if ss[t][3] <= ss[t+1][3]:
      popped += 1
      t+=1
    else:
      popped += 1
    
  t +=1
  if t >= len(s)-1:
    break
 
print(len(s)-popped)

Submission status: Runtime Error

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

rangeList = []
for element in XLList:
    Xi = element[0]
    Li = element[1]
    rangeList.append(range(Xi-Li, Xi+Li))

rangeList = sorted(rangeList, key=lambda x: min(x))

tmpList = []
tmpElement = rangeList[0]
for i in range(N):
    continueFlg = True

    prevElement = tmpElement
    tmpElement = rangeList[i]
    if i != N - 1:
        nextElement = rangeList[i+1]

    minPrev = min(prevElement)
    maxPrev = max(prevElement)
    minTmp = min(tmpElement)
    maxTmp = max(tmpElement)
    minNext = min(nextElement)
    maxNext = max(nextElement)
    if minNext < minTmp < maxNext or \
            minNext < maxTmp < maxNext or \
            minTmp < minNext < maxTmp or \
            minTmp < maxNext < maxTmp:
        continueFlg = False

    if continueFlg:
        tmpList.append(rangeList[i])

print(len(tmpList))

Submission status: Runtime Error

Solution code:
n = int(input())
"""
x = []
l = {}
for i in range(n):
  x_tmp, l_tmp = map(int,input().split(' '))
  x.append(x_tmp)
  l[x_tmp] = l_tmp
"""
x = [0] * n
l = {} 
for i in range(n):
  x_tmp, l_tmp = map(int,input().split(' '))
  x[i] = x_tmp
  l[x_tmp] = l_tmp


x.sort()
  
if n == 0:
  nRem = 0
elif n == 1:
  nRem = 0
else:
  cnt=0
  for inf_loop in range(n):
    nLoop = n-1-cnt
    for i in range(nLoop):
        a = x[i]+l[x[i]]
        b = x[i+1]-l[x[i+1]]
        print(a,b)
        
        if a > b:
          if i == 0:
            del x[i+1], l[x[i+1]]
          else:
            del x[i], l[x[i]]
            
          cnt += 1
          break

    if i == nLoop-1:
      break
  nRem = n - cnt
  
print(nRem)

Submission status: Runtime Error

Solution code:
N = int(input())
P = [list(map(int,input().split())) for i in range(N)]
P.sort()
for i in range(N-1):
    for j in range(N-1):
        if sum(P[i]) <=(P[j+i+1][0]-P[j+i+1][1]):
            break
        else:
            P[j+i+1]=[-1,-1]

P=[s for s in P if s != [-1,-1]]
print(len(P))

Submission status: Runtime Error

Solution code:
N = int(input())
R = []
lx = []
ll = []
for i in range(N):
  X, L = map(int, input().split())
  R.append(X)
  lx.append(X)
  ll.append(L)
for j in range(1, N-1):
  right = lx[j] + ll[j]
  left = lx[j+1] - ll[j+1]
  if left > right:
    R.remove(j)
print(len(R))

Submission status: Runtime Error

Solution code:
n = int(input())
XL = [list(map(int, input().split())) for _ in range(n)]
N = 0
for x, l in XL:
    N = max(N, x+l)
# N: 処理する区間の長さ
INF = 2**31-1

LV = (N-1).bit_length()
N0 = 2**LV
data = [0]*(2*N0)
lazy = [0]*(2*N0)

def gindex(l, r):
    L = (l + N0) >> 1; R = (r + N0) >> 1
    lc = 0 if l & 1 else (L & -L).bit_length()
    rc = 0 if r & 1 else (R & -R).bit_length()
    for i in range(LV):
        if rc <= i:
            yield R
        if L < R and lc <= i:
            yield L
        L >>= 1; R >>= 1

# 遅延伝搬処理
def propagates(*ids):
    for i in reversed(ids):
        v = lazy[i-1]
        if not v:
            continue
        lazy[2*i-1] += v; lazy[2*i] += v
        data[2*i-1] += v; data[2*i] += v
        lazy[i-1] = 0

# 区間[l, r)にxを加算
def update(l, r, x):
    *ids, = gindex(l, r)
    propagates(*ids)

    L = N0 + l; R = N0 + r
    while L < R:
        if R & 1:
            R -= 1
            lazy[R-1] += x; data[R-1] += x
        if L & 1:
            lazy[L-1] += x; data[L-1] += x
            L += 1
        L >>= 1; R >>= 1
    for i in ids:
        data[i-1] = min(data[2*i-1], data[2*i])

# 区間[l, r)内の合計を求める
def query(l, r):
    propagates(*gindex(l, r))
    L = N0 + l; R = N0 + r

    s = 0
    while L < R:
        if R & 1:
            R -= 1
            s += data[R-1]
        if L & 1:
            s += data[L-1]
            L += 1
        L >>= 1; R >>= 1
    return s


for x, l in XL:
    update(x-l, x+l, 1)

tmp = [0] * N
for i in range(len(XL)):
    mn = XL[i][0] - XL[i][1]
    mx = XL[i][0] + XL[i][1]
    XL[i].append(query(mn, mx))

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

LV = (N-1).bit_length()
N0 = 2**LV
data = [0]*(2*N0)
lazy = [0]*(2*N0)

cnt = 0
for x, l, z in XL:
    if query(x-l, x+l) == 0:
        cnt += 1
        update(x-l, x+l, 1)

print(cnt)

Submission status: Runtime Error

Solution code:


N = int(input())
array = []
for x in range(N):
  array.append(list(map(int, input().split())))
  array = sorted(array, key = lambda x:x[0])
  #print(array)
if N==1:
  print(1)
elif N==2:
  if dist(array[0], array[1]):
    print(2)
  else:
    print(1)
else:
  
  index = array[0][0]
  count = 1
  for p in range(1, N):
    if index + array[p-1][1] < array[p][0]:
      count += 1
  
  print(count)

Submission status: Runtime Error

Solution code:
def judge_notouch(lefts,rights):
    res=None
    touch=0
    attach_i,attach_j=None,None
    for i in range(N-1):
        breaked=0
        for j in range(i+1,N):
            if rights[i]>lefts[j]:
                touch=1
                attach_i=i
                attach_j=j
                breaked=1
                break
        if breaked:
            break

    if touch:
        temp=range(len(lefts))
        temp.pop(attach_i)
        drop_i=judge_notouch(lefts[temp],rights[temp])

        temp=range(len(lefts))
        temp.pop(attach_j)
        drop_j=judge_notouch(lefts[temp],rights[temp])

        res=min(drop_i,drop_j)

    else:
        res=0

    return res



    


N=int(input())
XL=[]

for i in range(N):
    x,l=input().split(" ")
    XL.append([int(x),int(l)])

XL.sort()

attach=[[0]*N for i in range(N) ]

right=[xl[0]+xl[1] for xl in XL]
left=[xl[0]-xl[1] for xl in XL]

ans=judge_notouch(left,right)

print(N-ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())

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

LR.sort()

tree = np.eye(N, dtype=bool)

is_now = np.zeros(N, dtype=bool)
for y, lr, idx in LR:
  if lr == 1:
    is_now[idx] = True
    tree[idx] += is_now
  else:
    is_now[idx] = False

tree += tree.T

a = np.sum(tree)
B = np.argsort(tree.sum(axis=0))[::-1]

for i, b in enumerate(B):
  if a == N:
    break
  tree[b] = tree[:, b] = False
  tree[b, b] = True
  a = np.sum(tree)

print(N - i)

Submission status: Runtime Error

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

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


x = [xl[i][0] for i in range(n)]
l = [xl[i][1] for i in range(n)]
left = [x[i]-l[i] for i in range(n)]
right= [x[i]+l[i] for i in range(n)]

import bisect
rinsetu=[]
for i in range(n):
    migite   = bisect.bisect_left(left, right[i])
    hidarite = bisect.bisect_right(right, left[i]) 
#    print(migite,hidarite)
    migite_catch   = list(range(i+1,migite) )
    hidarite_catch = list(range(hidarite,i) )
    rinsetu.append( hidarite_catch + migite_catch )
#    rinsetu.append( migite_catch )

# n=6
# rinsetu=[[1,2],[0,2,3],[0,1,3,4],[1,2],[2,5],[4]]
def remove_oya1(lis,c):
    neighbor = lis[:]
    i0=c
    for i in range(n):
        if len(neighbor[i]) == 1:
            oya=neighbor[i][0]
            for r in neighbor[oya]:
                neighbor[r].remove(oya)
            neighbor[oya]=[]
            i0+=1
    return neighbor, i0

def remove_biggest(lis,c):
    neighbor = lis[:]
    i0=c
    to_delete=0
    max_len=0
    for i in range(n):
        if len(neighbor[i]) > max_len:
            max_len=len(neighbor[i]) 
            to_delete=i
    
    oya=neighbor[to_delete]
    for r in oya:
        neighbor[r].remove(to_delete)
    neighbor[to_delete]=[]
    i0+=1
    return neighbor,i0

ans = 0
if sum(len(r) for r in rinsetu)==0:
    print(n)
else:
    rinsetu,ans = remove_oya1(rinsetu,ans)
while True:
    if sum(len(r) for r in rinsetu) > 0:
        rinsetu,ans = remove_biggest(rinsetu,ans)
    else:
        print(n-ans)
        break
    
    if sum(len(r) for r in rinsetu) > 0:
        rinsetu,ans = remove_oya1(rinsetu,ans)
    else:
        print(n-ans)
        break

Submission status: Runtime Error

Solution code:
n = int(input())
L = []
num_dic = {}
len_dic = {}
for i in range(n):
    tmp = []
    x,l = map(int,input().split())
    num_dic[x] = list(range(x-l+1,x+l))
    len_dic[x] = 2*l+1
 
 
L = sorted(len_dic.items(),key=lambda x:x[0])
#L.append((-1,-1))
# greedy
#print(L)
#print(num_dic)
ans = 0
before = set(num_dic[L[0][0]])
#print(L)
#print(num_dic)
for i in range(0,len(L)-1):
    tmp = before & set(num_dic[L[i+1][0]])
    #print("----")
    #print(tmp,len(tmp))
    kaburi = len(tmp)
    if kaburi == 0:
        before = before | set(num_dic[L[i+1][0]])
    else:
        ans += 1
print(n-ans)

Submission status: Runtime Error

Solution code:
listx=[]
listl=[]
i=0
j=0
r=0
n=int(input())

while i<n:
  i+=1
  a, b = map(int, input().split())
  listx.append(a)
  listl.append(b)

if(4<=n):
  while j<n-2:
    if(listx[j]+listl[j] > listx[j+1]-listl[j+1]):
      r+=1
      if(listx[j+1]+listl[j+1] > listx[j+2]-listl[j+2]):
        r-=1
    j+=1

  if(listx[n-2]+listl[n-2] > listx[n-1]-listl[n-1]):
    r+=1
    if(listx[n-1]+listl[n-1] > listx[n]-listl[n]):
      r-=1
    if(listx[n-2]+listl[n-2] > listx[n]-listl[n]):
      r+=1

else:
  if(listx[0]+listl[0] > listx[1]-listl[1]):
    r+=1
    if(listx[1]+listl[1] > listx[2]-listl[2]):
      r-=1
    if(listx[0]+listl[0] > listx[2]-listl[2]):
      r+=1
  if(listx[1]+listl[1] > listx[2]-listl[2]):
    r+=1
print(n-r)

Submission status: Runtime Error

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

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


x = [xl[i][0] for i in range(n)]
l = [xl[i][1] for i in range(n)]
left = [x[i]-l[i] for i in range(n)]
right= [x[i]+l[i] for i in range(n)]

import bisect
rinsetu=[]
for i in range(n):
    migite   = bisect.bisect_left(left, right[i])
    hidarite = bisect.bisect_right(right, left[i]) 
#    print(migite,hidarite)
    migite_catch   = list(range(i+1,migite) )
    hidarite_catch = list(range(hidarite,i) )
    rinsetu.append( hidarite_catch + migite_catch )
#    rinsetu.append( migite_catch )

# n=6
# rinsetu=[[1,2],[0,2,3],[0,1,3,4],[1,2],[2,5],[4]]


ans = 0
if sum(len(r) for r in rinsetu)==0:
    print(n)
else:
    rinsetu,ans = remove_oya1(rinsetu,ans)
while True:
    if sum(len(r) for r in rinsetu) > 0:
        rinsetu,ans = remove_biggest(rinsetu,ans)
    else:
        print(n-ans)
        break
    
    if sum(len(r) for r in rinsetu) > 0:
        rinsetu,ans = remove_oya1(rinsetu,ans)
    else:
        print(n-ans)
        break

def remove_oya1(lis,c):
    neighbor = lis[:]
    i0=c
    for i in range(n):
        if len(neighbor[i]) == 1:
            oya=neighbor[i][0]
            for r in neighbor[oya]:
                neighbor[r].remove(oya)
            neighbor[oya]=[]
            i0+=1
    return neighbor, i0

def remove_biggest(lis,c):
    neighbor = lis[:]
    i0=c
    to_delete=0
    max_len=0
    for i in range(n):
        if len(neighbor[i]) > max_len:
            max_len=len(neighbor[i]) 
            to_delete=i
    
    oya=neighbor[to_delete]
    for r in oya:
        neighbor[r].remove(to_delete)
    neighbor[to_delete]=[]
    i0+=1
    return neighbor,i0

Submission status: Runtime Error

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-2):
    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: Runtime Error

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-2):
    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: Runtime Error

Solution code:
n= int(raw_input())
d = []
for i in range(n):

	r, l= raw_input().split(" ")
	left_most = int(r) - int(l)
	d.append([int(r),int(l),left_most])
    
s = []
s = sorted(d, key=lambda tup: tup[2])

  
t=0
popped = 0
for i in s:
  x_current = s[t][0]
  x_next = s[t+1][0]
  l_current = s[t][1]
  l_next = s[t+1][1]
  
  if (x_current + l_current) > (x_next - l_next):
    # current interserts with next
    # pop next
    popped += 1
    t+=1
  t +=1
  if t >= len(s)-1:
    break

print(len(s)-popped)

Submission status: Runtime Error

Solution code:
listx=[]
listl=[]
i=0
j=0
r=0
n=int(input())

while i<n:
  i+=1
  a, b = map(int, input().split())
  listx.append(a)
  listl.append(b)

if(4<=n):
  while j<n-2:
    if(listx[j]+listl[j] >= listx[j+1]-listl[j+1]):
      r+=1
      if(listx[j+1]+listl[j+1] >= listx[j+2]-listl[j+2]):
        r-=1
    j+=1

  if(listx[n-2]+listl[n-2] >= listx[n-1]-listl[n-1]):
    r+=1
    if(listx[n-1]+listl[n-1] >= listx[n]-listl[n]):
      r-=1
    if(listx[n-2]+listl[n-2] >= listx[n]-listl[n]):
      r+=1

else:
  if(listx[0]+listl[0] >= listx[1]-listl[1]):
    r+=1
    if(listx[1]+listl[1] >= listx[2]-listl[2]):
      r-=1
    if(listx[0]+listl[0] >= listx[2]-listl[2]):
      r+=1
  if(listx[1]+listl[1] >= listx[2]-listl[2]):
    r+=1
print(n-r)

Submission status: Runtime Error

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: Runtime Error

Solution code:
n = int(input())
x = []
l = {}
for i in range(n):
  x_tmp, l_tmp = map(int,input().split(' '))
  x.append(x_tmp)
  l[x_tmp] = l_tmp

x.sort()
  
if n == 0:
  nRem = 0
elif n == 1:
  nRem = 0
else:
  cnt=0
  for inf_loop in range(n):
    nLoop = n-1-cnt
    for i in range(nLoop):
        a = x[i]+l[x[i]]
        b = x[i+1]-l[x[i+1]]
        
        if a > b:
          if i == 0:
            del x[i+1], l[x[i+1]]
          else:
            del x[i], l[x[i]]
            
          cnt += 1
          break

    if i == nLoop-1:
      break
  nRem = n - cnt
  
print(nRem)

Submission status: Runtime Error

Solution code:
# coding: utf-8

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

robots = sorted(robots)
eliminated = 0

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

print(N - eliminated)

Submission status: Runtime Error

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

input_l = []

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


for k in range(len(input_l)-1):
    for i in range(0, len(input_l) - 1 - k):
        if int(input_l[i][0]) > int(input_l[i+1][0]):
            x = input_l[i]
            input_l[i] = input_l[i+1]
            input_l[i+1] = x

for j in range(len(input_l)-1):
    if (int(input_l[j][0]) + int(input_l[j][-1])) - (int(input_l[j+1][0]) - int(input_l[j+1][-1])) > 0:
        counter += 1
        del input_l[j+1]
        j -= 1
print(num - counter)

Submission status: Runtime Error

Solution code:
N = int(input())
XL = []
for _ in range(N):
    x, l = map(int, input().split())
    XL.append([x, l])
XL.sort()
ans = 1
prev = XL[0]
dp = [[0] * 2] * N
dp[0][0] = 0
dp[0][1] = 1
for i in range(1, N):
    x, l = XL[i]
    if x - prev[0] - 1  - (l + prev[1] -1 )>= 0:
        dp[i][1] = max(dp[i-1][0], dp[i-1][1]) + 1
        dp[i][0] = max(dp[i-1][0], dp[i-1][1])
        prev = [x, l]
    else:
        dp[i][0] = max(dp[i-1][0], dp[i-1][1])
print(max(dp[i][1], dp[i][0]))

Submission status: Runtime Error

Solution code:
N = int(input())
P = [list(map(int,input().split())) for i in range(N)]
P.sort()
for i in range(N-1):
    for j in range(N-1):
        if sum(P[i]) <=P[j+i+1][0]:
            break
        else:
            P[j+i+1]=[-1,-1]

P=[s for s in P if s != [-1,-1]]
print(len(P))

Submission status: Runtime Error

Solution code:
n = int(input())
L = []
num_dic = {}
len_dic = {}
for i in range(n):
    tmp = []
    x,l = map(int,input().split())
    num_dic[x] = list(range(x-l+1,x+l))
    len_dic[x] = 2*l+1
 
 
L = sorted(len_dic.items(),key=lambda x:x[1])
#L.append((-1,-1))
# greedy
#print(L)
#print(num_dic)
ans = 0
before = num_dic[L[0][0]]
#print(L)
#print(num_dic)
for i in range(0,len(L)-1):
    tmp = set(before) & set(num_dic[L[i+1][0]])
    #print("----")
    #print(tmp,len(tmp))
    kaburi = len(tmp)
    if kaburi == 0:
        before = num_dic[L[i+1][0]]
    else:
        ans += 1
print(n-ans)

Submission status: Runtime Error

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

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

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

cnt = [None]*(10**9)
ans = [0 for _ in range(n)]

for i in range(n):
    for j in range(xl[i][0] - xl[i][1] + 1, xl[i][0] + xl[i][1]):
        if cnt[j] == None:
            cnt[j] = 1
        else:
            break
        if j == xl[i][0] + xl[i][1]-1:
            ans[i] = 1

print(sum(ans))

Submission status: Runtime Error

Solution code:
N = int(input())
XL = []
for _ in range(N):
    x, l = map(int, input().split())
    XL.append([x, l])
XL.sort()
ans = 1
prev = XL[0]
dp = [[0] * N for _ in range(N)]
dp[0][0] = 0
dp[0][1] = 1
for i in range(1, N):
    x, l = XL[i]
    if x - prev[0] - 1  - (l + prev[1] -1 )>= 0:
        dp[i][1] = max(dp[i-1][0], dp[i-1][1]) + 1
        dp[i][0] = max(dp[i-1][0], dp[i-1][1])
        prev = [x, l]
    else:
        dp[i][0] = max(dp[i-1][0], dp[i-1][1])
print(max(dp[i][1], dp[i][0]))