Buggy python submission (verdict: Time Limit Exceeded):
import sys
from heapq import heappush, heappop
input = sys.stdin.readline

num, person = map(int, input().split())
arr = []

for i in range(num):
    s, t, x = map(int, input().split())
    arr.append((s - x - 0.5, 1, x, i))
    arr.append((t - x - 0.5, 0, x, i))

for i in range(person):
    d = int(input())
    arr.append((d,))

arr.sort()

heap = []
done = set()

for elem in arr:
    if len(elem) == 1:
        while heap and heap[0][1] in done:
            heappop(heap)
        if heap:
            print(heap[0][0])
        else:
            print(-1)
        continue

    time, kind, x, i = elem
    if kind:
        heappush(heap, (x, i))
    else:
        done.add(i)


Fixed submission:
import sys
from heapq import heappush, heappop
from collections import defaultdict
input = sys.stdin.readline

num, person = map(int, input().split())
arr = []

for i in range(num):
    s, t, x = map(int, input().split())
    arr.append((s - x - 0.5, 1, x, i))
    arr.append((t - x - 0.5, -1, x, i))

for i in range(person):
    d = int(input())
    arr.append((d,))

arr.sort()

heap = []
done = defaultdict(int)

for elem in arr:
    if len(elem) == 1:
        d = elem[0]
        while heap and done[heap[0][1]] and d > done[heap[0][1]]:
            heappop(heap)
        if heap:
            print(heap[0][0])
        else:
            print(-1)
        continue

    time, kind, x, i = elem
    if kind == 1:
        heappush(heap, (x, i))
    elif kind == -1:
        done[i] = time

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    n, q = map(int, input().split())
    dic = {}
    stxs = [list(map(int, input().split())) for i in range(n)]
    stxs.sort(key=lambda x:x[2])

    for s, t, x in stxs:
        left = max(0, s - x)
        right = max(0, t - x)

        for i in range(left, right):
            if i not in dic:
                dic[i] = x

    ds = [int(input()) for _ in range(q)]

    for d in ds:
        if d in dic:
            print(dic[d])
        else:
            print(-1)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
from heapq import heappush, heappop
from collections import defaultdict
input = sys.stdin.readline

num, person = map(int, input().split())
arr = []

for i in range(num):
    s, t, x = map(int, input().split())
    arr.append((s - x - 0.5, 1, x, i))
    arr.append((t - x - 0.5, -1, x, i))

for i in range(person):
    d = int(input())
    arr.append((d,))

arr.sort()

heap = []
done = defaultdict(int)

for elem in arr:
    if len(elem) == 1:
        d = elem[0]
        while heap and done[heap[0][1]] and d > done[heap[0][1]]:
            heappop(heap)
        if heap:
            print(heap[0][0])
        else:
            print(-1)
        continue

    time, kind, x, i = elem
    if kind == 1:
        heappush(heap, (x, i))
    elif kind == -1:
        done[i] = time

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    n, q = map(int, input().split())
    dic = {}
    stxs = [list(map(int, input().split())) for i in range(n)]
    stxs.sort(key=lambda x:x[2])

    for s, t, x in stxs:
        left = max(0, s - x)
        right = max(0, t - x)

        for i in range(left, right):
            if i not in dic:
                dic[i] = x

    ds = [int(input()) for _ in range(q)]

    for d in ds:
        if d in dic:
            print(dic[d])
        else:
            print(-1)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
from heapq import heappush, heappop
from collections import defaultdict
input = sys.stdin.readline

num, person = map(int, input().split())
arr = []

for i in range(num):
    s, t, x = map(int, input().split())
    arr.append((s - x - 0.5, 1, x, i))
    arr.append((t - x - 0.5, -1, x, i))

for i in range(person):
    d = int(input())
    arr.append((d,))

arr.sort()

heap = []
done = defaultdict(int)

for elem in arr:
    if len(elem) == 1:
        d = elem[0]
        while heap and done[heap[0][1]] and d > done[heap[0][1]]:
            heappop(heap)
        if heap:
            print(heap[0][0])
        else:
            print(-1)
        continue

    time, kind, x, i = elem
    if kind == 1:
        heappush(heap, (x, i))
    elif kind == -1:
        done[i] = time