Problem: There is an infinitely long street that runs west to east, which we consider as a number line.  There are N roadworks scheduled on this street. The i-th roadwork blocks the point at coordinate X_i from time S_i - 0.5 to time T_i - 0.5.  Q people are standing at coordinate 0. The i-th person will start the coordinate 0 at time D_i, continue to walk with speed 1 in the positive direction and stop walking when reaching a blocked point.  Find the distance each of the Q people will walk.

Submission attempts (in order):
import heapq
n, q = map(int, input().split())
event = []
for _ in range(n):
    s, t, x = map(int, input().split())
    event.append((s-x, 1, x))
    event.append((t-x, -1, x))

event.sort(key=lambda y: y[0])
heap = []
xs = set([])

d = [int(input()) for _ in range(q)]
ans = [-1] * q
index = 0
for t, query, x in event:
    if d[index] < t:
        if not xs:
            pass
        else:
            while heap:
                tmp = heapq.heappop(heap)
                if tmp in xs:
                    heapq.heappush(tmp)
                    ans[index] = tmp
                    break
            print("----------")
        index += 1
        if index == q:
            break

    if query == 1:
        xs.add(x)
        heapq.heappush(heap, x)
    else:
        
        xs.remove(x)
    

print("\n".join(map(str, ans)))





import heapq
n, q = map(int, input().split())
event = []
for _ in range(n):
    s, t, x = map(int, input().split())
    event.append((s-x, 1, x))
    event.append((t-x, -1, x))

event.sort()
heap = []
xs = set([])

d = [int(input()) for _ in range(q)]
ans = [-1] * q
index = 0
for t, query, x in event:
    if d[index] < t:
        if not xs:
            pass
        else:
            while heap:
                tmp = heapq.heappop(heap)
                if tmp in xs:
                    heapq.heappush(heap, tmp)
                    ans[index] = tmp
                    break
        index += 1
        if index == q:
            break

    if query == 1:
        xs.add(x)
        heapq.heappush(heap, x)
    else:
        xs.remove(x)

    cnt[t] -= 1

while index < q:
    while heap:
        tmp = heapq.heappop(heap)
        if tmp in xs:
            heapq.heappush(heap, tmp)
            ans[index] = tmp
            break
    index += 1

print("\n".join(map(str, ans)))





import heapq
n, q = map(int, input().split())
event = []
for _ in range(n):
    s, t, x = map(int, input().split())
    event.append((s-x, 1, x))
    event.append((t-x, -1, x))

event.sort()
heap = []
xs = set([])

d = [int(input()) for _ in range(q)] + [10**9 + 7]
ans = [-1] * q
index = 0
for t, query, x in event:
    while d[index] < t:
        if not xs:
            pass
        else:
            while heap:
                tmp = heapq.heappop(heap)
                if tmp in xs:
                    heapq.heappush(heap, tmp)
                    ans[index] = tmp
                    break
        index += 1

    if query == 1:
        xs.add(x)
        heapq.heappush(heap, x)
    else:
        xs.remove(x)


while index < q:
    while heap:
        tmp = heapq.heappop(heap)
        if tmp in xs:
            heapq.heappush(heap, tmp)
            ans[index] = tmp
            break
    index += 1

print("\n".join(map(str, ans)))





Verdicts: Runtime Error

Runtime Error

Accepted