Problem p03033 (python)

Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 15 16:58:00 2019

@author: YudNK
"""
import bisect as bs

N, Q = map(int, input().split())
E = []
for i in range(N):
    s, t, x = map(int, input().split())
    a = [s - x, t - x, x] #イベント
    E.append(a)
E.sort(key = lambda x: x[2])
D = []
for i in range(Q):
    D.append(int(input()))

ans = [-1]*Q
check = [-1]*Q

for e in E:
    l = bs.bisect_left(D, e[0])
    r = bs.bisect_left(D, e[1])
    while l < r:
        if check[l] == -1:  
            ans[l] = e[2]
            check[l] = r
            l += 1
        else:
            l = check[l]
        
[print(i) for i in ans]

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 15 16:58:00 2019

@author: YudNK
"""
import bisect as bs

N, Q = map(int, input().split())
E = []
for i in range(N):
    s, t, x = map(int, input().split())
    a = [s - x, t - x, x] #イベント
    E.append(a)
E.sort(key = lambda x: x[2])
D = []
for i in range(Q):
    D.append(int(input()))

ans = [-1]*Q
check = [-1]*Q

for e in E:
    l = bs.bisect_left(D, e[0])
    r = bs.bisect_left(D, e[1])
    while l != r:
        if check[l] == -1:  
            ans[l] = e[2]
            check[l] = r
            l += 1
        else:
            l = check[l]
        
[print(i) for i in ans]

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 15 16:58:00 2019

@author: YudNK
"""
#import heapq as hp
#import bisect as bs

N, Q = map(int, input().split())
E = []
for i in range(N):
    s, t, x = map(int, input().split())
    app = [s - x, -1, x] #追加イベント
    rem = [t - x, -2, x] #削除イベント
    E.append(app)
    E.append(rem)
for i in range(Q):
    d = [int(input()), i, -1]
    E.append(d)
E.sort(key = lambda x:x[0])

ans = []
stopX = []

for e in E:
    if e[1] == -1:
        stopX.heappush(e[2])
    elif e[1] == -2:
        stopX.remove(e[2])
    else:
        if len(stopX) != 0:
            ans.append(stopX[0])
        else:
            ans.append(-1)
[print(i) for i in ans]

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 15 16:58:00 2019

@author: YudNK
"""
import heapq as hp
import bisect as bs

N, Q = map(int, input().split())
E = []
for i in range(N):
    s, t, x = map(int, input().split())
    app = [s - x, 1, x]
    rem = [t - x, -1, x]
    E.append(app)
    E.append(rem)
D = [int(input()) for i in range(Q)]
E.sort(key = lambda x:x[0])

ans = []
stopX = []

for j in range(len(E)):
    while D[0] < E[j][0]:
        if len(stopX) == 0:
            ans.append(-1)
            hp.heappop(D)
        else:
            ans.append(stopX[0])
            hp.heappop(D)
    if E[j][1] == 1:
        hp.heappush(stopX, E[j][2])
    else:
        index = bs.bisect_left(stopX,E[j][2])
        stopX.pop(index)

while len(ans) != Q:
    ans.append(-1)
[print(i) for i in ans]

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 15 16:58:00 2019

@author: YudNK
"""
import heapq as hp
import bisect as bs

N, Q = map(int, input().split())
E = []
for i in range(N):
    s, t, x = map(int, input().split())
    app = [s - x, 1, x]
    rem = [t - x, -1, x]
    E.append(app)
    E.append(rem)
E.sort(key = lambda x:x[0])
D = [int(input()) for i in range(Q)]

ans = []
stopX = []

for j in range(len(E)):
    while D[0] < E[j][0]:
        if len(stopX) == 0:
            ans.append(-1)
            hp.heappop(D)
        else:
            ans.append(stopX[0])
            hp.heappop(D)
    if E[j][1] == 1:
        hp.heappush(stopX, E[j][2])
    else:
        index = bs.bisect_left(stopX,E[j][2])
        stopX.pop(index)

while len(ans) != Q:
    ans.append(-1)
[print(i) for i in ans]

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 15 16:58:00 2019

@author: YudNK
"""
import heapq as hp
import bisect as bs

N, Q = map(int, input().split())
E = []
for i in range(N):
    s, t, x = map(int, input().split())
    app = [s - x, 1, x]
    rem = [t - x, -1, x]
    E.append(app)
    E.append(rem)
E.sort(key = lambda x:x[0])
D = [int(input()) for i in range(Q)]

ans = []
stopX = []

for j in range(len(E)):
    while D[0] < E[j][0]:
        if len(stopX) == 0:
            ans.append(-1)
            hp.heappop(D)
        else:
            ans.append(stopX[0])
            hp.heappop(D)
    if E[j][1] == 1:
        hp.heappush(stopX, E[j][2])
    else:
        index = bs.bisect_left(stopX,E[j][2])
        stopX.pop(index)
[print(i) for i in ans]