Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappop, heappush

N, Q = map(int, input().split())

event = []
for _ in range(N) :
    s, t, x = map(int, input().split())
    event.append([s - x, t - x, x])

D = [int(input()) for _ in range(Q)]

event.sort()

closed = []
ei = 0

for d in D :
    while ei < N and event[ei][0] <= d :
        heappush(closed, (event[ei][2], event[ei][1]))
        ei += 1
    while closed and closed[0][1] <= d :
        heappop(closed)
    
    if closed :
        print(closed[0][0])
    else :
        print(-1)

Fixed submission:
import sys, heapq
input = sys.stdin.readline

N, Q = map(int, input().split())

event = []
for _ in range(N) :
    s, t, x = map(int, input().split())
    event.append([s - x, t - x, x])

D = [int(input()) for _ in range(Q)]

event.sort()

closed = []
ei = 0

for d in D :
    while ei < N and event[ei][0] <= d :
        heapq.heappush(closed, (event[ei][2], event[ei][1]))
        ei += 1
    while closed and closed[0][1] <= d :
        heapq.heappop(closed)
    
    if closed :
        print(closed[0][0])
    else :
        print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq

N, Q = map(int, input().split())

event = []
for _ in range(N) :
    s, t, x = map(int, input().split())
    event.append([s - x, t - x, x])

D = [int(input()) for _ in range(Q)]

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

ei = 0

for d in D :
    while ei < N and event[ei][0] <= d :
        heapq.heappush(closed, (event[ei][2], event[ei][1]))
        ei += 1
    while len(closed) > 0 and closed[0][1] <= d :
        heapq.heappop(closed)
    
    if len(closed) == 0 :
        print(-1)
    else :
        print(closed[0][0])

Fixed submission:
import sys, heapq
input = sys.stdin.readline

N, Q = map(int, input().split())

event = []
for _ in range(N) :
    s, t, x = map(int, input().split())
    event.append([s - x, t - x, x])

D = [int(input()) for _ in range(Q)]

event.sort()

closed = []
ei = 0

for d in D :
    while ei < N and event[ei][0] <= d :
        heapq.heappush(closed, (event[ei][2], event[ei][1]))
        ei += 1
    while closed and closed[0][1] <= d :
        heapq.heappop(closed)
    
    if closed :
        print(closed[0][0])
    else :
        print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N, Q = map(int, input().split())

event = []
for _ in range(N) :
    s, t, x = map(int, input().split())
    event.append([s - x, True, x])
    event.append([t - x, False, x])

D = [int(input()) for _ in range(Q)]

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

ei = 0

for d in D :
    while ei < 2 * N and event[ei][0] <= d :
        if event[ei][1] :
            bisect.insort_left(constraction, event[ei][2])
        else :
            constraction.pop(bisect.bisect_left(constraction, event[ei][2]))
        ei += 1

    if len(constraction) == 0 :
        print(-1)
    else :
        print(min(constraction))

Fixed submission:
import sys, heapq
input = sys.stdin.readline

N, Q = map(int, input().split())

event = []
for _ in range(N) :
    s, t, x = map(int, input().split())
    event.append([s - x, t - x, x])

D = [int(input()) for _ in range(Q)]

event.sort()

closed = []
ei = 0

for d in D :
    while ei < N and event[ei][0] <= d :
        heapq.heappush(closed, (event[ei][2], event[ei][1]))
        ei += 1
    while closed and closed[0][1] <= d :
        heapq.heappop(closed)
    
    if closed :
        print(closed[0][0])
    else :
        print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
STX = []
for _ in range(N) :
    s, t, x = map(int, input().split())
    STX.append([s - x, t - x, x])

D = [int(input()) for _ in range(Q)]

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

for d in D :
    flag = True
    for s, t, x in STX :
        if s <= d < t :
            print(x)
            flag = False
            break
    if flag :
        print(-1)


Fixed submission:
import sys, heapq
input = sys.stdin.readline

N, Q = map(int, input().split())

event = []
for _ in range(N) :
    s, t, x = map(int, input().split())
    event.append([s - x, t - x, x])

D = [int(input()) for _ in range(Q)]

event.sort()

closed = []
ei = 0

for d in D :
    while ei < N and event[ei][0] <= d :
        heapq.heappush(closed, (event[ei][2], event[ei][1]))
        ei += 1
    while closed and closed[0][1] <= d :
        heapq.heappop(closed)
    
    if closed :
        print(closed[0][0])
    else :
        print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
STX = [[int(i) for i in input().split()] for _ in range(N)]
D = [int(input()) for _ in range(Q)]

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

for d in D :
    flag = True
    for s, t, x in STX :
        if s - 0.5 <= d + x <= t - 0.5 :
            print(x)
            flag = False
            break
    if flag :
        print(-1)

Fixed submission:
import sys, heapq
input = sys.stdin.readline

N, Q = map(int, input().split())

event = []
for _ in range(N) :
    s, t, x = map(int, input().split())
    event.append([s - x, t - x, x])

D = [int(input()) for _ in range(Q)]

event.sort()

closed = []
ei = 0

for d in D :
    while ei < N and event[ei][0] <= d :
        heapq.heappush(closed, (event[ei][2], event[ei][1]))
        ei += 1
    while closed and closed[0][1] <= d :
        heapq.heappop(closed)
    
    if closed :
        print(closed[0][0])
    else :
        print(-1)