Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
X.sort(key = lambda x: x[2])
X.append([-1, 1, X[-1][2] + 1])

def quitConst(t):
  nextx = [x for x in X if x[1] > t + x[2] or x[0] == -1]
  return nextx
def startConst(t):
  nextx = [x for x in X if x[0] <= t + x[2] or x[0] == -1]
  return nextx
for _ in range(Q):
  current = 0
  start = int(input())
  X = quitConst(start)
  XX = startConst(start)
  for x in XX:
    current = x[2]
    if x[0] <= current + start < x[1]:
      break
  if current == XX[-1][2]:
    print(-1)
  else:
    print(current)

Fixed submission:
from bisect import bisect_left as bl
N, Q = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
X.sort(key = lambda x: x[2])
Y = [int(input()) for _ in range(Q)]
res = [-1] * Q
jump = [-1] * Q
for s,t,x in X:
  l=bl(Y,s - x)
  r=bl(Y,t - x)
  while l < r:
    s = jump[l]
    if s == -1:
      res[l] = x
      jump[l] = r
      l += 1
    else:
      l = s
print(*res,sep = '\n')

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
X.sort(key = lambda x: x[2])
X.append([-1, 1, X[-1][2] + 1])

def quitConst(t):
  nextx = [x for x in X if x[1] > t + x[2] or x[0] == -1]
  return nextx

for _ in range(Q):
  current = 0
  start = int(input())
  X = quitConst(start)
  for x in X:
    current = x[2]
    if x[0] <= current + start < x[1]:
      break
  if current == X[-1][2]:
    print(-1)
  else:
    print(current)

Fixed submission:
from bisect import bisect_left as bl
N, Q = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
X.sort(key = lambda x: x[2])
Y = [int(input()) for _ in range(Q)]
res = [-1] * Q
jump = [-1] * Q
for s,t,x in X:
  l=bl(Y,s - x)
  r=bl(Y,t - x)
  while l < r:
    s = jump[l]
    if s == -1:
      res[l] = x
      jump[l] = r
      l += 1
    else:
      l = s
print(*res,sep = '\n')

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
X.sort(key = lambda x: x[2])
X.append([-1, 1, X[-1][2] + 1])

def quitConst(t):
  nextx = [x for x in X if x[1] > t or x[0] == -1]
  return nextx

for _ in range(Q):
  current = 0
  start = int(input())
  X = quitConst(start)
  for x in X:
    current = x[2]
    if x[0] <= current + start < x[1]:
      break
  if current == X[-1][2]:
    print(-1)
  else:
    print(current)

Fixed submission:
from bisect import bisect_left as bl
N, Q = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
X.sort(key = lambda x: x[2])
Y = [int(input()) for _ in range(Q)]
res = [-1] * Q
jump = [-1] * Q
for s,t,x in X:
  l=bl(Y,s - x)
  r=bl(Y,t - x)
  while l < r:
    s = jump[l]
    if s == -1:
      res[l] = x
      jump[l] = r
      l += 1
    else:
      l = s
print(*res,sep = '\n')

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
X.sort(key = lambda x: x[2])
X.append([-1, 1, X[-1][2] + 1])

def quitConst(t):
  nextx = [x for x in X if x[1] > t or x[0] == -1]
  return nextx

for _ in range(Q):
  current = 0
  start = int(input())
  X = quitConst(start)
  for x in X:
    current = x[2]
    if x[0] <= current + start < x[1]:
      break
  if current == X[-1][2]:
    print(-1)
  else:
    print(current)

Fixed submission:
from bisect import bisect_left as bl
N, Q = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
X.sort(key = lambda x: x[2])
Y = [int(input()) for _ in range(Q)]
res = [-1] * Q
jump = [-1] * Q
for s,t,x in X:
  l=bl(Y,s - x)
  r=bl(Y,t - x)
  while l < r:
    s = jump[l]
    if s == -1:
      res[l] = x
      jump[l] = r
      l += 1
    else:
      l = s
print(*res,sep = '\n')

Buggy python submission (verdict: Time Limit Exceeded):
inputa = list(map(int, input().split()))
inputb = []
for i in range(inputa[0]):
  inputb.append(list(map(int, input().split())))
#座標、開始時間の順にソート
inputb.sort(key=lambda x:(x[2],x[0]))
#歩く人の処理
for i in range(inputa[1]):
  inputc = int(input())
  time = 0 + inputc
  walk = 0
  broken = 0
  #工事の気配あるとこまで歩く
  for j in range(inputa[0]):
    walk = inputb[j][2]
    time = inputc + inputb[j][2]
    if (time >= inputb[j][0]) and (time < inputb[j][1]):
      print(walk)
      broken = 1
      break
  if broken == 0:
    print(-1)

Fixed submission:
from bisect import bisect_left as bl
N, Q = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
X.sort(key = lambda x: x[2])
Y = [int(input()) for _ in range(Q)]
res = [-1] * Q
jump = [-1] * Q
for s,t,x in X:
  l=bl(Y,s - x)
  r=bl(Y,t - x)
  while l < r:
    s = jump[l]
    if s == -1:
      res[l] = x
      jump[l] = r
      l += 1
    else:
      l = s
print(*res,sep = '\n')