Problem p02796 (python)

Fixed submission:
n=int(input())
xlr=[[] for _ in range(n)]

for i in range(n):
    xx,ll = map(int,input().split())
    xlr[i] = [xx,ll,xx-ll,xx+ll]
    
xlr.sort(key = lambda x:x[3])

ans=1
right=xlr[0][-1]
for i in range(1,n):
    if right <= xlr[i][2]:
        ans+=1
        right=xlr[i][-1]

print(ans)

Buggy submission (verdict: Runtime Error):
#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

Buggy submission (verdict: Runtime Error):
#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

Buggy submission (verdict: Runtime Error):
#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