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

def main():
  n, q = map(int, input().split())
  event = []
  stop = set()
  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()
  event.append((float("inf"), 0, 0))
  D = list(map(int, read().split()))
  now = 0
  for t, b, x in event:
    m = min(stop) if stop else -1
    while t > D[now]:
      print(m)
      now += 1
      if now == q:
        exit()
    if b == 1:
      stop.add(x)
    else:
      stop.remove(x)
      
if __name__ == "__main__":
  main()

Fixed submission:
import sys
input = sys.stdin.readline
read = sys.stdin.read

import heapq

def main():
  n, q = map(int, input().split())
  event = []
  stop = set()
  minque = []
  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()
  event.append((float("inf"), 0, 0))
  D = list(map(int, read().split()))
  now = 0
  for t, b, x in event:
    while minque and minque[0] not in stop:
      heapq.heappop(minque)
    m = minque[0] if minque else -1
    while t > D[now]:
      print(m)
      now += 1
      if now == q:
        exit()
    if b == 1:
      stop.add(x)
      heapq.heappush(minque, x)
    else:
      stop.remove(x)
      
if __name__ == "__main__":
  main()

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

def main():
  n, q = map(int, input().split())
  event = []
  stop = set()
  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()
  event.append((float("inf"), 0, 0))
  D = list(map(int, read().split()))
  now = 0
  for t, b, x in event:
    m = min(stop) if stop else -1
    while t > D[now]:
      print(m)
      now += 1
      if now == q:
        exit()
    if b == 1:
      stop.add(x)
    else:
      stop.remove(x)
      
if __name__ == "__main__":
  main()

Fixed submission:
import sys
input = sys.stdin.readline
read = sys.stdin.read

import heapq

def main():
  n, q = map(int, input().split())
  event = []
  stop = set()
  minque = []
  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()
  event.append((float("inf"), 0, 0))
  D = list(map(int, read().split()))
  now = 0
  for t, b, x in event:
    while minque and minque[0] not in stop:
      heapq.heappop(minque)
    m = minque[0] if minque else -1
    while t > D[now]:
      print(m)
      now += 1
      if now == q:
        exit()
    if b == 1:
      stop.add(x)
      heapq.heappush(minque, x)
    else:
      stop.remove(x)
      
if __name__ == "__main__":
  main()

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

def main():
  n, q = map(int, input().split())
  event = []
  stop = set()
  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()
  event.append((float("inf"), 0, 0))
  D = list(map(int, read().split()))
  now = 0
  for t, b, x in event:
    while t > D[now]:
      if stop:
        print(min(stop))
      else:
        print(-1)
      now += 1
      if now == q:
        exit()
    if b == 1:
      stop.add(x)
    else:
      stop.remove(x)
      
if __name__ == "__main__":
  main()

Fixed submission:
import sys
input = sys.stdin.readline
read = sys.stdin.read

import heapq

def main():
  n, q = map(int, input().split())
  event = []
  stop = set()
  minque = []
  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()
  event.append((float("inf"), 0, 0))
  D = list(map(int, read().split()))
  now = 0
  for t, b, x in event:
    while minque and minque[0] not in stop:
      heapq.heappop(minque)
    m = minque[0] if minque else -1
    while t > D[now]:
      print(m)
      now += 1
      if now == q:
        exit()
    if b == 1:
      stop.add(x)
      heapq.heappush(minque, x)
    else:
      stop.remove(x)
      
if __name__ == "__main__":
  main()

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
event = []
stop = set()
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()
event.append((float("inf"), 0, 0))
D = [int(input()) for _ in range(q)]
now = 0
for t, b, x in event:
  while t > D[now]:
    if stop:
      print(min(stop))
    else:
      print(-1)
    now += 1
    if now == q:
      exit()
  if b == 1:
    stop.add(x)
  else:
    stop.remove(x)

Fixed submission:
import sys
input = sys.stdin.readline
read = sys.stdin.read

import heapq

def main():
  n, q = map(int, input().split())
  event = []
  stop = set()
  minque = []
  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()
  event.append((float("inf"), 0, 0))
  D = list(map(int, read().split()))
  now = 0
  for t, b, x in event:
    while minque and minque[0] not in stop:
      heapq.heappop(minque)
    m = minque[0] if minque else -1
    while t > D[now]:
      print(m)
      now += 1
      if now == q:
        exit()
    if b == 1:
      stop.add(x)
      heapq.heappush(minque, x)
    else:
      stop.remove(x)
      
if __name__ == "__main__":
  main()