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=[]
L=[]
XA=[]
XB=[]
Q=[0]*N
for i in range(N):
  x,l=map(int,input().split())
  X.append(x)
  L.append(l)
for i in range(N):
  XA.append(X[i]-L[i])
  XB.append(X[i]+L[i])
S=sorted(list(zip(XA,XB)))
cnt=0
#print(S)
i=0
while i<N-1:
  if i==0:
    if S[i][1]>S[i+1][0]:
      cnt=cnt+1
      if S[i][1]<=S[i+1][1]:
        S.pop(i+1)
      else:
        S.pop(i)
      i=i+1
    else:
      i=i+1
  else:
    if S[i-1][1]>S[i][0]:
      cnt=cnt+1
      S.pop(i)
      i=i+1
    else:
      i=i+1
#print(cnt)
#print(S)
print(N-cnt)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
import sys
from collections import OrderedDict

input = sys.stdin.readline
r = OrderedDict()

n = int(input())
for _ in range(n):
    x, l = map(int, input().split())
    r[x-l] = x+l

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

cp = 0
fp = 1
ans = n
while True:
    if r[cp][1] > r[fp][0]:
        ans -= 1
        fp += 1
    else:
        cp = fp
        fp += 1

    if n <= fp:
        break

print(ans)

Submission status: Runtime Error

Solution code:
from bisect import bisect,bisect_left
def main():
    n=int(input())
    xl=sorted([tuple(map(int,input().split())) for _ in range(n)])
    llist=[i-j for i,j in xl]
    rlist=[i+j for i,j in xl]
    d=[]
    dlen=[]
    tf=[False]*n
    c=0
    for j,i in enumerate(xl):
        larm=i[0]-i[1]
        rarm=i[0]+i[1]
        lidx=bisect(rlist,larm)
        ridx=bisect_left(llist,rarm)
        tmp = set(range(lidx,ridx))
        tmp.discard(j)
        d.append(tmp)
        dlen.append([ridx-lidx,j])
        if ridx-lidx<=1:
            tf[j]=True
            c+=1
    dlen=sorted(dlen)
    while True:
        if c==n:
            break
        p=dlen.pop(-1)[1]
        for i in d[p]:
            d[i].discard(p)
            if not d[i]:
                c+=1
                tf[i]=True
        d[p]=set()
        c+=1
    print(sum(tf))
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
X ,L = [],[]
# line = [0]*100100
line = [0]*100000000
half = 100000000 //2
for _ in range(N):
  a, b= map(int, input().split())
  X.append(a)
  L.append(b)

for i in range(N):
  print("【{},{}】".format(X[i],L[i]))
  for k in range(X[i]-L[i]+1,X[i]+L[i]):
    line[k+half] += 1
count = 0
past = -1
for l in line:
  if l >= 2 and l != past:
    count += l-1
  past = l
print(N-count)

Submission status: Runtime Error

Solution code:
N = int(input())
XL ={}
cnt = 0
for i in range(N):
  x,l = map(int,input().split())
  XL[x]=l
#print(XL)
XL_sorted = sorted(XL.items(), key=lambda XL:-XL[1])
XL = sorted(XL.items(), key=lambda XL:-XL[0])
for i in XL_sorted:
  if XL is None or XL_sorted is None:
    break
  #print(i)
  for j in XL:
    #print(j)
    if j[0] < i[0]:
      if j[0]+j[1] > i[0]-i[1]:
        cnt += 1
        XL_sorted=XL_sorted.remove(i)
        XL=XL.remove(i)
    if j[0] < i[0]-i[1]:
      break
print(N-cnt)

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.copy()
    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.copy()
    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:
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
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[1]+listl[1] >= listx[2]-listl[2]):
    r+=1
print(n-r)

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_by(target_list):
    return range(int(target_list[0]) - int(target_list[1]), int(target_list[0]) + int(target_list[1]))


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_by(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:
N=int(input())
s=[list(map(int,input().split())) for i in range(N)]
A=N
c=0
s.sort(key=lambda x: x[0])

Check=[[s[i][0]-s[i][1],s[i][0]+s[i][1]] for i in range(N)]

for j in range(1,N):

    if Check[j-1][1] > Check[j][0]:
        c=c+1
        Check.remove(Check[j])
        j=j-1
        N=N-1
        if j == N:
            break
    
print(A-c)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [[0,0] for _ in range(n)]

for i in range(n):
    a[i][0],a[i][1]=map(int,input().split())
a.sort()
cnt=0
now=0
temp=1
for i in range(n-1):
    if a[now][0]+a[now][1]>a[now+temp][0]+a[now+temp][1]:
        now+=temp
        cnt+=1
    elif  a[now+temp][0]-a[now+temp][1]<a[now][0]+a[now][1]:
        temp+=1
        cnt+=1
    else:
        now+=temp
        temp=1

print(n-cnt)

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

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.zeros([N, 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[idx] += is_now


tree += tree.T

a = np.sum(tree, axis=0)
while (a != 1).any():
  idx = a.argmax()
  tree = np.delete(np.delete(tree, idx, 0), 1)
  a = np.sum(tree, axis=0)

print(len(tree))

Submission status: Runtime Error

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
stocks = 0

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

print (n -remove)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
XL = []
ans = np.zeros(10 ** 8, dtype='float32')
for _ in range(N):
    x, l = map(int, input().split())
    XL.append([x, l])
XL = sorted(XL, key=lambda x: x[1])
a = 0
for i in range(N):
    x, l = XL[i]
    if not 1 in ans[max(0, x - l + 1):min(10**9-1, x + l - 1)+1]:
        ans[min(10 ** 9-1, x + l - 1)] = 1
        ans[max(0, x - l + 1)] = 1
        a += 1
print(a)

Submission status: Runtime Error

Solution code:
#n,m = map(int,input().split())
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 = 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:
n = int(input())
x = []
for i in range(n):
    X,L = map(int, input().split())
    x.append([X-L,X+L])
x.sort()
y = [0]*n
ans = 0
for i in range(n-2):
    if x[i][1]>x[i+2][0]:
        ans +=1
        y[i] = -1
    elif x[i][1]>x[i+1][0] and y[i]==0:
        y[i] +=1
        y[i+1] +=1
    elif x[i][1]>x[i+1][0] and y[i]==1:
        ans +=1
        y[i] = -1
        y[i-1] = 0
        continue
if x[-1][0]<x[n-3][1]:
    y[-1] = -1
    ans +=1
elif x[-1][0]<x[n-2][1]:
    y[-1] +=1
    y[n-2] +=1

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

Submission status: Runtime Error

Solution code:
H=int(input())
K=H
a=[]
b=[0]*H
k=1
s=0

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

  
while k!=0:
  b=[0]*H
  k=0
  for i in range(H):
    for c in range(H):
      if i!=c:
         if abs(a[i][0]-a[c][0])<a[i][1]+a[c][1]:
            b[i]+=1
  for i in range(H):
    k+=b[i]
    
  if k!=0:
    a.pop([idx for idx,val in enumerate(b) if val>=k//2])
    H=len(a)

print(len(a))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
XL = []
import numpy as np
for _ in range(N):
    XL.append([int(x) for x in input().split()])
XL = np.array(sorted(XL))
XL_max = []
XL_min = []
for i in XL:
    XL_max.append(i[0] + i[1])
    XL_min.append(i[0] - i[1])
A = [0] * N
for i in range(N):
    cnt = 0
    left = sorted(XL_max[:i])
    right = sorted(XL_min[i+1:])
    cnt += i - np.searchsorted(left, XL_min[i], side = "right") 
    cnt += np.searchsorted(right, XL_max[i], side = "left")
    A[i] = cnt
cnt = np.array(sorted(A, reverse=True), np.int64)
cnt = np.cumsum(cnt)
if cnt[-1] == 0:
    print(n)
else:
    print(N - (np.searchsorted(cnt, cnt[-1] // 2) + 1))

Submission status: Runtime Error

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

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

cnt = [0 for _ in range(10**7)]
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] == 0:
            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())
l = []
for i in range(n):
    l.append(tuple(map(int,input().split())))
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
        if i+2 <= n:
            R2 = l[i+2][0]-l[i+2][1]
            if L <= R2:
                l[i+1] = l[i]
        else:
            l[i+1] = l[i]
print(ans)

Submission status: Runtime Error

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


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

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

count = N
#line = [0] * (2*(10**9) +1)
XL = sorted(XL)


itv.sort()

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

Submission status: Runtime Error

Solution code:
n = int(input())

d = {}
for i in range(n):
  t1, t2 = map(int, input().split())
  d[t1] = t2

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

i = 0
c = []
c.append(1 if d[0][0] + d[0][1] > d[1][0] - d[1][1] else 0)
for i in range(1,n-1):
  x0 = d[i-1][0] + d[i-1][1]
  x1 = d[i][0] - d[i][1]
  y1 = d[i][0] + d[i][1]
  y2 = d[i+1][0] - d[i+1][1]
  t = 0
  if x0 > x1:
    t += 1
  if y1 > y2:
    t += 1
  c.append(t)
c.append(1 if d[n-2][0] + d[n-2][1] > d[n-1][0] - d[n-1][1] else 0)

e = 0
i = 1
while i < n-1:
  if c[i] == 2:
    e += 1
    c[i-1] -= 1
    c[i] -= 2
    c[i+1] -= 1
    i += 1
  i += 1

print(n-e-sum(c)//2)

Submission status: Runtime Error

Solution code:
    N = int(input())
    y = [[None] * N for _ in range(N)]
    L = [0]*N
    d = {}
    max = 0
    del_count = 0
    first = 0
    for i in range(N):
      y[i]= list(map(int,list(input().split())))
    count = 0
    x = sorted(y)
    for z in x:
      if count == 0:
        max = z[0] + z[1]
      elif max > z[0] - z[1]:
        del_count +=1
      else:
        max = z[0] + z[1]
    print(N-del_count)

Submission status: Runtime Error

Solution code:
r=0
n=int(input())

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

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

print(n-r)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
n = int(input())
r = []
for i in range(n):
    x, l = map(int, input().split())
    r.append((x - l + 1, x + l - 1))
r.sort()
am = [[] for _ in range(n)]
for i in range(n):
    for j in range(i + 1, n):
        if r[i][1] < r[j][0]:
            break
        am[i].append(j)
        am[j].append(i)
while sum(len(mi) for mi in am):
    maxi, maxd = 0, 0
    for i, mi in enumerate(am):
        li = len(mi)
        if li > maxd:
            maxi, maxd = i, li
    for pi in am[maxi]:
        am[pi].remove(maxi)
    am.pop(maxi)
    n -= 1
print(n)

Submission status: Runtime Error

Solution code:
N = int(input())
X = []
L = []
XL = []
for i in range(N):
  temp = list(map(int, input().split()))
  X.append(temp[0])
  L.append(temp[1])
  XL.append(temp[0]+temp[1])
  
num = 0
area = [0] * (max(XL)-1)
for i in range(N):
  flag = 0
  if(L[i]==1):
    if(area[X[i]-1]==0):
      area[X[i]-1]=1
    else:
      num += 1
  else:
    for j in range(1,2*L[i]):
      if(X[i]-1-L[i]+j>=0):
        if(area[X[i]-1-L[i]+j]==0):
          flag = 0
        else:
          flag = 1
          num += 1
          break
  if(flag==0):
    for j in range(1,2*L[i]):
      if(X[i]-1-L[i]+j>=0):
        area[X[i]-1-L[i]+j]=1
    
print(N-num)

Submission status: Runtime Error

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    MAX = 10 ** 10

    XL = [tuple(map(int, input().split())) for _ in range(N)]
    XL = sorted(XL, key=lambda x: (x[0], x[1]))

    ans = 0
    res = [0] * MAX
    for x, l in XL:
        a = x - l
        a = a if a > 0 else 0
        b = x + l - 1
        b = b if b < MAX else (MAX - 1)

        if sum(res[a:b]) == 0:
            res[a:b] = [1] * (b-a+1)
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

ls = sorted([[i-j, i+j] for i, j in xl], key=lambda x: x[1])
i, dr = 0, 0
while True:
    if len(ls)<=1:
        break
    a, b = ls[i], ls[i+1]
    if a[1]>b[0]:
        dr += 1
        ls.pop(i+1)
    else:
        i += 1
        if i+1 >= len(ls):
            break
print(len(ls))

Submission status: Runtime Error

Solution code:
N=int(input())

a=[]
k=[]

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

p=[]

z=[]
out=[]
for i in a:

    x=int(i[0])
    y=int(i[1])
    z=[x-y,int(x),x+y]

    p.append(z)
A=[]

counter=0
for j in p:
    x0=int(j[0])
    x1=int(j[1])
    x2=int(j[2])
    if counter==0:

        A=[x0,x1,x2]
        counter+=1

        continue
    if x0<A[2]:
        a.pop(counter)

        counter+=1
        continue
    A=[x0,x1,x2]
    counter+=1

print(len(a))

Submission status: Runtime Error

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
stocks = 0

while(1):
    flag = True
    
    for k in range(n-1):
      if (x[k+1 + stocks][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
        if n-2>k:
          stocks +=1
        k -=1
      else:
        stocks = 0

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

Submission status: Runtime Error

Solution code:
n=int(input())
li=[]
for i in range(0,n):
    flag=True
    x,l=map(int, input().split())
    mi=x-l
    ma=x+l
    for j in li:
	if j[0] < mi < ma < j[1]:
            flag=False
            break
    if flag:
	li.append([mi,ma])
print(len(li))

Submission status: Runtime Error

Solution code:
import math
import pandas as pd
import sys
sys.setrecursionlimit(2147483647)
n=int(input())
x=[0]*n
l=[0]*n
start=[0]*n
end=[0]*n

for i in range(0,n):
    [tmp_x,tmp_l]=input().split()
    x[i]=int(tmp_x)
    l[i]=int(tmp_l)


df =  pd.DataFrame({'X':x,'Length':l})
df = df.sort_values(by=['X'])
df = df.reset_index(drop=True)

k =n
check = 0
while check ==0:
    both=[0]*k
    for i in range(0,k):
        if i == 0:
            if df['X'][i]+df['Length'][i]>(df['X'][i+1]-df['Length'][i+1]):
                both[i] = 1
        elif i==k-1:
            if df['X'][i-1]+df['Length'][i-1] > df['X'][i]-df['Length'][i]:
                both[i] = 1
        else:
            if df['X'][i-1]+df['Length'][i-1] > df['X'][i]-df['Length'][i]:
                both[i]=both[i]+1
            if df['X'][i]+df['Length'][i]>(df['X'][i+1]-df['Length'][i+1]):
                both[i]=both[i]+1
                
    try:
        rm_idx=both.index(2)
        df = df.drop([rm_idx])
        df = df.reset_index(drop=True)
        k = k-1
    except ValueError:
        check =1

print(df.shape[0])

Submission status: Runtime Error

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
stocks = 0

while(1):
    flag = True
    
    for k in range(n-1):
      if (x[k+1 + stocks][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
        if n-2>k:
          stocks +=1
        k -=1
      else:
        stocks = 0

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

Submission status: Runtime Error

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

robots = sorted(robots, key=lambda x: x[0])
rightest_point = robots[0][0] + robots[0][1] - 1
ans = 0
# 無理やり一体目を置いた時
for i in range(1, len(robots)):
    if robots[i][0]-robots[i][1] + 1 < rightest_point:
        ans += 1
        continue
    else:
        rightest_point = robots[i][0]+robots[i][1] - 1
first = N-ans

# 1体目を置かない場合
rightest_point = robots[1][0] + robots[1][1] - 1
ans = 0
for i in range(2, len(robots)):
    # print("rightest_point: ", rightest_point)
    if robots[i][0]-robots[i][1] + 1 < rightest_point:
        ans += 1
        continue
    else:
        rightest_point = robots[i][0]+robots[i][1] - 1
# print("rightest_point: ", rightest_point)
second = N-ans-1
print(max(first, second))

Submission status: Runtime Error

Solution code:
import bisect
N = int(input())
MAX = [[]for _ in range(N)]
MIN = [[]for _ in range(N)]
for i in range(N):
    x,l = map(int,input().split())
    MAX[i] = x+l
    MIN[i] = x-l
MAX_a = sorted(MAX[:])
MIN_a = sorted(MIN[:])
A = [[0]for _ in range(N)]
for i in range(N):
    A[i] = bisect.bisect_left(MIN_a,MAX[i])-(i+1)
    A[i] += i-bisect.bisect_right(MAX_a,MIN[i])
A = sorted(A,reverse=True)
a = sum(A)
ans = 0
while True:
    if a == 0:
        break
    a -= A[ans]*2
    ans += 1
print(N-ans)

Submission status: Runtime Error

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

robots_sorted = sorted(robots, key=lambda x: x['x'])
ans = n
i = 0
while((robots_sorted[0]['x'] + robots_sorted[0]['l']) > (robots_sorted[1]['x'] - robots_sorted[1]['l'])):
    if(robots_sorted[0]['l'] > robots_sorted[1]['l'] * 2):
        robots_sorted.pop(0)
    else:
        robots_sorted.pop(1)

while(i < n-1):
    if((robots_sorted[i]['x'] + robots_sorted[i]['l']) > (robots_sorted[i+1]['x'] - robots_sorted[i+1]['l'])):
        if(i == n-2):
            if(robots_sorted[n-2]['l'] * 2 >= robots_sorted[n-1]['l']):
                robots_sorted.pop(i)
            else:
                robots_sorted.pop(i+1)
        elif(robots_sorted[i]['l'] > robots_sorted[i+1]['l']):
            robots_sorted.pop(i)
        else:
            robots_sorted.pop(i+1)
        i += -1
        n += -1
    i += 1

print(n)

Submission status: Runtime Error

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

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

max_cnt = 0

for s in range(n):
    if max_cnt >= n - s + 1:
        break

    rxs2 = rxs_[s:]

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

    if max_cnt < cnt:
        max_cnt = cnt

print(max_cnt)

Submission status: Runtime Error

Solution code:
N = int(input())
X = [0] * N
L = [0] * N
for i in range(N):
  X[i], L[i] = map(int, input().split())
x_l=[]
for i in range(N):
  x_l.append(X[i]+L[i])
a = [0] * (max(x_l)+1)
t=0
t_list=[]
for j in range(N):
  for i in range(j,N):
    if a[max(0,X[i]-L[i]+1):X[i]+L[i]]==[0]*len(a[max(0,X[i]-L[i]+1):X[i]+L[i]]):
      a[max(0,X[i]-L[i]+1):X[i]+L[i]]=[1]*len(a[max(0,X[i]-L[i]+1):X[i]+L[i]])
      t+=1
  t_list.append(t)
  a = [0] * max(x_l)
  t=0
print(max(t_list))

Submission status: Runtime Error

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
stocks = 0

while(1):
    flag = True
    
    for k in range(n-1):
      if (x[k+1 + stocks][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
        if n-2>k:
          stocks +=1
        k -=1
      else:
        stocks = 0

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

Submission status: Runtime Error

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    MAX = 10 ** 5 + 10

    XL = [tuple(map(int, input().split())) for _ in range(N)]
    XL = sorted(XL, key=lambda x: (x[0], x[1]))

    ans = 0
    res = [0] * MAX
    for x, l in XL:
        a = x - l
        a = a if a > 0 else 0
        b = x + l - 1
        b = b if b < MAX else (MAX - 1)

        if res[a] + res[b] == 0:
            res[a:b] = [1] * (b-a+1)
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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( abs(X_sort[i] - X_sort[i-1]) <= L_sort[i] or
       abs(X_sort[i+1] - X_sort[i]) <= L_sort[i+1]):
      X_sort[i]=X_sort[i-1]
      L_sort[i]=L_sort[i-1]
      cnt -= 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
print(cnt)

Submission status: Runtime Error

Solution code:
# coding: utf-8

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

robots = [[X[i]-L[i], X[i]+L[i]] for i in range(N)]
robots = sorted(robots, key=lambda x: x[1])
robots = sorted(robots, key=lambda x: x[0])

max_record = 0
right_max_dict = {robot[1]: None for robot in robots}


def rec(idx, right, n_robot, used):
    global max_record

    if idx == N:
        if n_robot > max_record:
            max_record = n_robot
        return None

    if used:
        old_right = right_max_dict[robots[idx][1]]
        if old_right is None:
            right_max_dict[robots[idx][1]] = n_robot
        else:
            if old_right >= n_robot:
                return None

    if right <= robots[idx][0]:
        rec(idx+1, robots[idx][1], n_robot+1, True)  # idx番目を使う
        rec(idx+1, right, n_robot, False)  # idx番目を使わない
    else:
        rec(idx+1, right, n_robot, False)  # idx番目を使わない


rec(0, -(10**9), 0, False)

print(max_record)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
xls = []
end = 0
for _ in range(n):
    x, l = map(int, input().split())
    end = max(end, x+l)
    xls.append([x-l, x+l])
    
line = np.zeros(end+1)
ans = 0
for i in xls:
    start = i[0]
    if start <= 0:
        start = 0
    line[start:i[1]-1] += 1
    if np.amax(line[start:i[1]]) <= 1:
        ans += 1
    else:
        line[start:i[1]] -= 1

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
xl = [[int(i) for i in input().split(' ')] for j in range(n)]
import numpy as np

ls = np.array([[i-j, i+j] for i, j in xl])
ls = ls[ls[:, 0].argsort()]
 
i, dr = 0, 0
while True:
    a, b = ls[i], ls[i+1]
    if a[1]>b[0]:
        dr += 1
        ls = np.delete(ls, i+1, 0)
    else:
        i += 1
        if i+1 >= len(ls):
            break
print(len(ls))

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
rs = [list(map(int, input().split())) for _ in range(n)]
rs = np.array(rs)
mn_mx = np.stack([rs[:, 0] - rs[:, 1], rs[:, 0] + rs[:, 1]], axis=1)
mn_mx = mn_mx[np.argsort(mn_mx[:, 1])]

cnt = 0
reach = None
for mn, mx in mn_mx:
    if reach is not None and mn < reach:
        continue
    reach = mx
    cnt += 1
print(cnt)

Submission status: Runtime Error

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

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

lr = sorted(lr)

remove = 0
skip = False

for i in range(1, n):
    if lr[i - 1][0] == lr[i][0]:
        remove += 1
    elif lr[i - 1][0] < lr[i][0] < lr[i - 1][1]:
        if not lr[i][0] < lr[i + 1][0] < lr[i][1]:
            remove += 1

print(n - remove)

Submission status: Runtime Error

Solution code:
N = int(input())
XL = []
ans = [0] * (10 ** 9)
for _ in range(N):
    x, l = map(int, input().split())
    XL.append([x, l])
XL = sorted(XL, key=lambda x: x[1])
a = 0
for i in range(N):
    x, l = XL[i]
    if not 1 in ans[max(0, x - l + 1):min(10**9-1, x + l - 1)+1]:
        ans[min(10 ** 9-1, x + l - 1)] = 1
        ans[max(0, x - l + 1)] = 1
        a += 1
print(a)