Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left as bisect
N,Q = map(int,input().split())
event = [tuple(map(int,input().split())) for i in range(N)]
D = [int(input()) for i in range(Q)]

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

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

for s,t,x in event:
    l = bisect(D,s-x)
    r = bisect(D,t-x)
    t = l
    while t < r:
        if neg[t] == -1:
            ans[t] = x
            neg[t] = r
            t += 1
        else:
            t = neg[t]

for i in range(Q):
    print(ans[i])

Fixed submission:
from bisect import bisect_left as bisect
N,Q = map(int,input().split())
event = [tuple(map(int,input().split())) for i in range(N)]
D = [int(input()) for i in range(Q)]

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

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

for s,t,x in event:
    l = bisect(D,s-x)
    r = bisect(D,t-x)
    t = l
    while t < r:
        if neg[t] == -1:
            ans[t] = x
            neg[t] = r
            t += 1
        else:
            t = neg[t]

for i in range(Q):
    print(ans[i])

Buggy python submission (verdict: Runtime Error):
 N,Q = map(int,input().split())
event = []
for i in range(N):
    s,t,x = map(int,input().split())
    event.append((s-x,x,1))
    event.append((t-x,x,-1))

s = set()

event.sort()
event.reverse()


for i in range(Q):
    D = int(input())
    f = False
    while event:
        t,x,e = event.pop()
        if D < t:
            f = True
            break
        if e == 1:
            s.add(x)
        else:
            s.remove(x)
    if len(s)==0:
        print(-1)
    else:
        print(min(s))
    if f:
        if e == 1:
            s.add(x)
        else:
            s.remove(x)

Fixed submission:
from bisect import bisect_left as bisect
N,Q = map(int,input().split())
event = [tuple(map(int,input().split())) for i in range(N)]
D = [int(input()) for i in range(Q)]

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

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

for s,t,x in event:
    l = bisect(D,s-x)
    r = bisect(D,t-x)
    t = l
    while t < r:
        if neg[t] == -1:
            ans[t] = x
            neg[t] = r
            t += 1
        else:
            t = neg[t]

for i in range(Q):
    print(ans[i])

Buggy python submission (verdict: Runtime Error):
s = set()

event.sort()
event.reverse()


for i in range(Q):
    D = int(input())
    f = False
    while event:
        t,x,e = event.pop()
        if D < t:
            f = True
            break
        if e == 1:
            s.add(x)
        else:
            s.remove(x)
    if len(s)==0:
        print(-1)
    else:
        print(min(s))
    if f:
        if e == 1:
            s.add(x)
        else:
            s.remove(x)

Fixed submission:
from bisect import bisect_left as bisect
N,Q = map(int,input().split())
event = [tuple(map(int,input().split())) for i in range(N)]
D = [int(input()) for i in range(Q)]

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

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

for s,t,x in event:
    l = bisect(D,s-x)
    r = bisect(D,t-x)
    t = l
    while t < r:
        if neg[t] == -1:
            ans[t] = x
            neg[t] = r
            t += 1
        else:
            t = neg[t]

for i in range(Q):
    print(ans[i])

Buggy python submission (verdict: Runtime Error):
N,Q = map(int,input().split())
event = []
for i in range(N):
    s,t,x = map(int,input().split())
    event.append((s-x,x,1))
    event.append((t-x,x,-1))

s = set()

event.sort()

for i in range(Q):
    D = int(input())
    while event:
        t,x,f = event.pop(0)
        if D < t:
            break
        if f == 1:
            s.add(x)
        else:
            s.remove(x)
    if len(s)==0:
        print(-1)
    else:
        print(min(s))
    if D < t:
        if f == 1:
            s.add(x)
        else:
            s.remove(x)

Fixed submission:
from bisect import bisect_left as bisect
N,Q = map(int,input().split())
event = [tuple(map(int,input().split())) for i in range(N)]
D = [int(input()) for i in range(Q)]

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

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

for s,t,x in event:
    l = bisect(D,s-x)
    r = bisect(D,t-x)
    t = l
    while t < r:
        if neg[t] == -1:
            ans[t] = x
            neg[t] = r
            t += 1
        else:
            t = neg[t]

for i in range(Q):
    print(ans[i])