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

import sys
input = sys.stdin.buffer.readline


def main():

    n, q = map(int, input().split())
    stx = [map(int, input().split()) for _ in range(n)]
    ds = [int(input()) for _ in range(q)]
    INF = 10 ** 9 + 1
    START = 1
    END = 0

    tfdi = []
    for i, (s, t, x) in enumerate(stx):
        t_start = max(0, s - x)
        t_end = max(0, t - x)
        if t_end == 0:
            continue

        tfdi.append((t_start, START, x, i))
        tfdi.append((t_end, END, x, i))

    tfdi.append((INF, START, INF, -1))
    tfdi.sort()

    hp = [(INF, -1)]
    ts = []
    dists = []
    t_prev = -1
    passed = set()
    for t, f, d, i in tfdi:
        if t != t_prev:
            ts.append(t_prev)
            while hp[0][1] in passed:
                heappop(hp)

            dists.append(hp[0][0])

        if f == START:
            heappush(hp, (d, i))
        else:
            passed.add(i)

        t_prev = t

    ts = np.array(ts, np.int64)
    ds = np.array(ds, np.int64)
    dists = np.array(dists, np.int64)

    idx = np.searchsorted(ts, ds, "right") - 1
    ans = dists[idx]
    ans[ans==INF] = -1
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()


Fixed submission:
from bisect import bisect_left

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

INF = 10 ** 9 + 1

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

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

for s, t, x in stx:
    l = bisect_left(d, s - x)
    r = bisect_left(d, t - x)

    while l < r:
        if nxt[l] == -1:
            ans[l] = x
            nxt[l] = r
            l += 1
        else:
            l = nxt[l]

print(*ans, sep="\n")

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

import sys
input = sys.stdin.buffer.readline


def main():

    n, q = map(int, input().split())
    stx = [list(map(int, input().split())) for _ in range(n)]
    ds = [int(input()) for _ in range(q)]
    INF = 10 ** 18
    START = 1
    END = 0

    tfdi = []
    for i, (s, t, x) in enumerate(stx):
        t_start = max(0, s - x)
        t_end = max(0, t - x)
        if t_end == 0:
            continue

        tfdi.append([t_start, START, x, i])
        tfdi.append([t_end, END, x, i])

    tfdi.append([INF, START, INF, -1])
    tfdi.sort()

    hp = [[INF, -1]]
    ts = []
    dists = []
    t_prev = -1
    passed = set()
    for t, f, d, i in tfdi:
        if t != t_prev:
            ts.append(t_prev)
            while hp[0][1] in passed:
                heappop(hp)

            dists.append(hp[0][0])

        if f == START:
            heappush(hp, [d, i])
        else:
            passed.add(i)

        t_prev = t

    ts = np.array(ts, np.int64)
    ds = np.array(ds, np.int64)
    dists = np.array(dists, np.int64)

    idx = np.searchsorted(ts, ds, "right") - 1
    ans = dists[idx]
    ans[ans==INF] = -1
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()


Fixed submission:
from bisect import bisect_left

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

INF = 10 ** 9 + 1

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

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

for s, t, x in stx:
    l = bisect_left(d, s - x)
    r = bisect_left(d, t - x)

    while l < r:
        if nxt[l] == -1:
            ans[l] = x
            nxt[l] = r
            l += 1
        else:
            l = nxt[l]

print(*ans, sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappop, heappush
from bisect import bisect_right
import numpy as np

n, q = map(int, input().split())
stx = [list(map(int, input().split())) for _ in range(n)]
ds = [int(input()) for _ in range(q)]
INF = 10 ** 18
START = 1
END = 0

tfdi = []
for i, (s, t, x) in enumerate(stx):
    t_start = max(0, s - x)
    t_end = max(0, t - x)
    if t_end == 0:
        continue

    tfdi.append([t_start, START, x, i])
    tfdi.append([t_end, END, x, i])

tfdi.append([INF, START, INF, -1])
tfdi.sort()

hp = [[INF, -1]]
ts = []
dists = []
t_prev = -1
passed = set()
for t, f, d, i in tfdi:
    if t != t_prev:
        ts.append(t_prev)
        while hp[0][1] in passed:
            heappop(hp)

        dists.append(hp[0][0])

    if f == START:
        heappush(hp, [d, i])
    else:
        passed.add(i)

    t_prev = t

ts = np.array(ts, np.int64)
ds = np.array(ds, np.int64)
dists = np.array(dists, np.int64)

idx = np.searchsorted(ts, ds, "right") - 1
ans = dists[idx]
ans[ans==INF] = -1
print(*ans, sep="\n")


Fixed submission:
from bisect import bisect_left

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

INF = 10 ** 9 + 1

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

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

for s, t, x in stx:
    l = bisect_left(d, s - x)
    r = bisect_left(d, t - x)

    while l < r:
        if nxt[l] == -1:
            ans[l] = x
            nxt[l] = r
            l += 1
        else:
            l = nxt[l]

print(*ans, sep="\n")

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

n, q = map(int, input().split())
stx = [list(map(int, input().split())) for _ in range(n)]
ds = [int(input()) for _ in range(q)]
INF = 10 ** 18
START = 1
END = 0

tfdi = []
for i, (s, t, x) in enumerate(stx):
    t_start = max(0, s - x)
    t_end = max(0, t - x)
    if t_end == 0:
        continue

    tfdi.append([t_start, START, x, i])
    tfdi.append([t_end, END, x, i])

tfdi.append([INF, START, INF, -1])
tfdi.sort()

hp = [[INF, -1]]
ts = []
dists = []
t_prev = -1
passed = set()
for t, f, d, i in tfdi:
    if t != t_prev:
        ts.append(t_prev)
        while hp[0][1] in passed:
            heappop(hp)

        dists.append(hp[0][0])

    if f == START:
        heappush(hp, [d, i])
    else:
        passed.add(i)

    t_prev = t

for d in ds:
    i = bisect_right(ts, d) - 1
    ans = dists[i]
    if ans == INF:
        ans = -1
    print(ans)


Fixed submission:
from bisect import bisect_left

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

INF = 10 ** 9 + 1

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

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

for s, t, x in stx:
    l = bisect_left(d, s - x)
    r = bisect_left(d, t - x)

    while l < r:
        if nxt[l] == -1:
            ans[l] = x
            nxt[l] = r
            l += 1
        else:
            l = nxt[l]

print(*ans, sep="\n")

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

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

INF = 10 ** 9 + 1

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

li.sort()
x_st = set([INF])
xxs = []
xs = [INF]

i = 0
for xx, check, x in li:
    if check == -1:
        x_st.remove(x)
    else:
        x_st.add(x)

    xxs.append(xx)
    xs.append(min(x_st))

for e in d:
    i = bisect_right(xxs, e)
    ans = xs[i]
    if ans == INF:
        ans = -1
    print(ans)


Fixed submission:
from bisect import bisect_left

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

INF = 10 ** 9 + 1

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

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

for s, t, x in stx:
    l = bisect_left(d, s - x)
    r = bisect_left(d, t - x)

    while l < r:
        if nxt[l] == -1:
            ans[l] = x
            nxt[l] = r
            l += 1
        else:
            l = nxt[l]

print(*ans, sep="\n")