Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
from bisect import bisect_left


def main():
    N, Q = map(int, input().split())
    XST = []
    for i in range(N):
        s, t, x = map(int, input().split())
        XST.append((x, s-x, t-x))
    XST.sort(reverse=True)
    D = [0]*Q
    for i in range(Q):
        D[i] = int(input())
    start = [set() for _ in range(Q)]
    end = [set() for _ in range(Q)]
    # Dはソートされている。
    for x, s, t in XST:
        # こっから！
        frm = bisect_left(D, s)
        to = bisect_left(D, t, lo=frm)
        # 数列の範囲を代入で更新して、値を取得する
        start[frm].add(x)
        end[to].add(x)
        # print(*stop, sep="\n")
        # for j in range(frm, to):
        #     stop[j] = x
    curr = set()
    for i in range(Q):
        curr |= start[i] - (start[i] & end[i])
        curr -= (end[i]-start[i])
        if len(curr) == 0:
            print(-1)
        else:
            print(min(curr))


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
from bisect import bisect_left, bisect_right
import heapq

INF = float("inf")


class ErasableHeap(object):
    # https://qiita.com/Salmonize/items/638da118cd621d2628d1
    def __init__(self):
        self.data = []
        self.event = []

    def push(self, x):
        return heapq.heappush(self.data, x)

    def erase(self, x):
        return heapq.heappush(self.event, x)

    def _check(self):
        while self.event and\
                self.data[0] == self.event[0]:
            heapq.heappop(self.data)
            heapq.heappop(self.event)

    def front(self):
        self._check()
        return self.data[0]

    def pop(self):
        self.check()
        return heapq.heappop(self.data)

    def __len__(self):
        self._check()
        return len(self.data)


def main():
    N, Q = map(int, input().split())
    XST = [0]*N
    for i in range(N):
        s, t, x = map(int, input().split())
        XST[i] = (x, s-x, t-x)
    D = [0]*Q
    for i in range(Q):
        D[i] = int(input())
    event = []
    for x, s, t in XST:
        event.append((s, 1, x))
        event.append((t, -1, x))

    event.sort()

    head = 0
    stack = ErasableHeap()
    for t, p, x in event:
        while D[head] < t:
            if len(stack) == 0:
                print(-1)
            else:
                print(stack.front())
            head += 1
            if head >= Q:
                return
        if p == 1:
            stack.push(x)
        else:
            stack.erase(x)

    while head < len(D):
        if len(stack) == 0:
            print(-1)
        else:
            print(stack.front())
        head += 1
        if head >= Q:
            return


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
from bisect import bisect_left, bisect_right
INF = float("inf")


def main():
    N, Q = map(int, input().split())
    XST = [0]*N
    for i in range(N):
        s, t, x = map(int, input().split())
        XST[i] = (x, s-x, t-x)
    XST.sort(reverse=True)
    D = [0]*Q
    for i in range(Q):
        D[i] = int(input())
    stop = [-1]*Q
    # print(D)
    # Dはソートされている。ラッキー！
    for x, s, t in XST:
        # こっから！
        # print("[{}, {})".format(s, t))
        frm = bisect_left(D, s)
        # ここまで！
        to = bisect_left(D, t, lo=frm)
        # print(frm, to)
        for j in range(frm, to):
            stop[j] = x
    print(*stop, sep="\n")


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
from bisect import bisect_left, bisect_right
import heapq

INF = float("inf")


class ErasableHeap(object):
    # https://qiita.com/Salmonize/items/638da118cd621d2628d1
    def __init__(self):
        self.data = []
        self.event = []

    def push(self, x):
        return heapq.heappush(self.data, x)

    def erase(self, x):
        return heapq.heappush(self.event, x)

    def _check(self):
        while self.event and\
                self.data[0] == self.event[0]:
            heapq.heappop(self.data)
            heapq.heappop(self.event)

    def front(self):
        self._check()
        return self.data[0]

    def pop(self):
        self.check()
        return heapq.heappop(self.data)

    def __len__(self):
        self._check()
        return len(self.data)


def main():
    N, Q = map(int, input().split())
    XST = [0]*N
    for i in range(N):
        s, t, x = map(int, input().split())
        XST[i] = (x, s-x, t-x)
    D = [0]*Q
    for i in range(Q):
        D[i] = int(input())
    event = []
    for x, s, t in XST:
        event.append((s, 1, x))
        event.append((t, -1, x))

    event.sort()

    head = 0
    stack = ErasableHeap()
    for t, p, x in event:
        while D[head] < t:
            if len(stack) == 0:
                print(-1)
            else:
                print(stack.front())
            head += 1
            if head >= Q:
                return
        if p == 1:
            stack.push(x)
        else:
            stack.erase(x)

    while head < len(D):
        if len(stack) == 0:
            print(-1)
        else:
            print(stack.front())
        head += 1
        if head >= Q:
            return


if __name__ == '__main__':
    main()