Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
stx = [tuple(int(x) for x in input().split()) for _ in range(n)]
d = [int(input()) for _ in range(q)]

e = []

for s, t, x in stx:
    e.append([s-x, 1, x])
    e.append([t-x, -1, x])

e.sort()
e.append([10 ** 9, 1, 10 ** 9])

h = set()
h.add(10 ** 9)
i = 0

for p in d:
    while e[i][0] <= p:
        if e[i][1] == 1:
            h.add(e[i][2])
        else:
            h.remove(e[i][2])
        i += 1
    ans = min(h)
    if ans == 10 ** 9:
        print(-1)
    else:
        print(min(h))


Fixed submission:
from bisect import bisect_left
from operator import itemgetter

n, q = map(int, input().split())
stx = [tuple(int(x) for x in input().split()) for _ in range(n)]
d = [int(input()) for _ in range(q)]

ans = [-1] * q
skip = [-1] * q

stx.sort(key=itemgetter(2))

for s, t, x in stx:
    L = bisect_left(d, s-x)
    R = bisect_left(d, t-x)
    while L < R:
        if skip[L] == -1:
            ans[L] = x
            skip[L] = R
            L += 1
        else:
            L = skip[L]

for x in ans:
    print(x)

Buggy python submission (verdict: Time Limit Exceeded):
#from bisect import bisect_left
#from operator import itemgetter

n, q = map(int, input().split())
stx = [tuple(int(x) for x in input().split()) for _ in range(n)]
d = [int(input()) for _ in range(q)]

ans = [-1] * q

#stx.sort(reverse=True, key=itemgetter(2))

e = []

for s, t, x in stx:
    e.append([s-x, 1, x])
    e.append([t-x, -1, x])

e.sort()
e.append([10 ** 9, 1, 10 ** 9])

h = set()
h.add(10 ** 9)
i = 0

for p in d:
    while e[i][0] <= p:
        if e[i][1] == 1:
            h.add(e[i][2])
        else:
            h.remove(e[i][2])
        i += 1
    ans = min(h)
    if ans == 10 ** 9:
        print(-1)
    else:
        print(min(h))

Fixed submission:
from bisect import bisect_left
from operator import itemgetter

n, q = map(int, input().split())
stx = [tuple(int(x) for x in input().split()) for _ in range(n)]
d = [int(input()) for _ in range(q)]

ans = [-1] * q
skip = [-1] * q

stx.sort(key=itemgetter(2))

for s, t, x in stx:
    L = bisect_left(d, s-x)
    R = bisect_left(d, t-x)
    while L < R:
        if skip[L] == -1:
            ans[L] = x
            skip[L] = R
            L += 1
        else:
            L = skip[L]

for x in ans:
    print(x)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
from operator import itemgetter

n, q = map(int, input().split())
stx = [tuple(int(x) for x in input().split()) for _ in range(n)]
d = [int(input()) for _ in range(q)]

ans = [-1] * q

stx.sort(reverse=True, key=itemgetter(2))

for s, t, x in stx:
    L = bisect_left(d, s-x)
    R = bisect_left(d, t-x)
    for i in range(L, R):
        ans[i] = x

for x in ans:
    print(x)

Fixed submission:
from bisect import bisect_left
from operator import itemgetter

n, q = map(int, input().split())
stx = [tuple(int(x) for x in input().split()) for _ in range(n)]
d = [int(input()) for _ in range(q)]

ans = [-1] * q
skip = [-1] * q

stx.sort(key=itemgetter(2))

for s, t, x in stx:
    L = bisect_left(d, s-x)
    R = bisect_left(d, t-x)
    while L < R:
        if skip[L] == -1:
            ans[L] = x
            skip[L] = R
            L += 1
        else:
            L = skip[L]

for x in ans:
    print(x)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
from operator import itemgetter

n, q = map(int, input().split())
stx = [tuple(int(x) for x in input().split()) for _ in range(n)]
d = [int(input()) for _ in range(q)]

ans = [-1] * q

stx.sort(reverse=True, key=itemgetter(2))

for s, t, x in stx:
    L = bisect_left(d, s-x)
    R = bisect_left(d, t-x)
    for i in range(L, R):
        ans[i] = x

for x in ans:
    print(x)

Fixed submission:
from bisect import bisect_left
from operator import itemgetter

n, q = map(int, input().split())
stx = [tuple(int(x) for x in input().split()) for _ in range(n)]
d = [int(input()) for _ in range(q)]

ans = [-1] * q
skip = [-1] * q

stx.sort(key=itemgetter(2))

for s, t, x in stx:
    L = bisect_left(d, s-x)
    R = bisect_left(d, t-x)
    while L < R:
        if skip[L] == -1:
            ans[L] = x
            skip[L] = R
            L += 1
        else:
            L = skip[L]

for x in ans:
    print(x)