Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

def main():
	N, Q = map(int, input().split())
	S, T, X = [0] * N, [0] * N, [0] * N
	
	for i in range(N):
		S[i], T[i], X[i] = map(int, input().split())
		
	D = [int(input()) for _ in range(Q)]
	
	event = [] #工事と人を１つのリストで管理: (時間, 出来事の種類, [工事の位置])
	#出来事の種類: (0: 工事の終了、1: 工事の開始、2: 人)
	working = [] #現在行われている工事のリスト
	n = 0 #現在行われている工事の数
	
	for i in range(Q):
		event.append((D[i], 2))
		
	for i in range(N):
		bisect.insort(event, (S[i] - X[i] - 0.5, 1, X[i]))
		bisect.insort(event, (T[i] - X[i] - 0.5, 0, X[i]))
		
	for l in event:
		if l[1] == 1:
			bisect.insort(working, l[2])
			n += 1
		elif l[1] == 0:
			del working[bisect.bisect(working, l[2]) - 1]
			n -= 1
		else:
			if n > 0:
				print(working[0])
			else:
				print(-1)
				
main()

Fixed submission:
import bisect
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N, Q = map(int, input().split())
S, T, X = [0] * N, [0] * N, [0] * N
work = []

for i in range(N):
	S[i], T[i], X[i] = map(int, input().split())
	work.append((X[i], S[i] - X[i], T[i] - X[i]))

D = [int(input()) for _ in range(Q)]

work.sort()
ans = [-1] * Q
skip = [-1] * Q

for i in range(N):
	left = bisect.bisect_left(D, work[i][1])
	right = bisect.bisect_left(D, work[i][2])
	
	while left < right:
		if skip[left] == -1:
			skip[left] = right
			ans[left] = work[i][0]
			left += 1
		else:
			left = skip[left]					
		
for i in ans:
	print(i)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N, Q = map(int, input().split())
S, T, X = [0] * N, [0] * N, [0] * N

for i in range(N):
	S[i], T[i], X[i] = map(int, input().split())
	
D = [int(input()) for _ in range(Q)]

event = [] #工事と人を１つのリストで管理: (時間, 出来事の種類, [工事の位置])
#出来事の種類: (0: 工事の終了、1: 工事の開始、2: 人)
working = [] #現在行われている工事のリスト
n = 0 #現在行われている工事の数

for i in range(Q):
	event.append((D[i], 2))
	
for i in range(N):
	bisect.insort(event, (S[i] - X[i] - 0.5, 1, X[i]))
	bisect.insort(event, (T[i] - X[i] - 0.5, 0, X[i]))
	
for l in event:
	if l[1] == 1:
		bisect.insort(working, l[2])
		n += 1
	elif l[1] == 0:
		del working[bisect.bisect(working, l[2]) - 1]
		n -= 1
	else:
		if n > 0:
			print(working[0])
		else:
			print(-1)

Fixed submission:
import bisect
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N, Q = map(int, input().split())
S, T, X = [0] * N, [0] * N, [0] * N
work = []

for i in range(N):
	S[i], T[i], X[i] = map(int, input().split())
	work.append((X[i], S[i] - X[i], T[i] - X[i]))

D = [int(input()) for _ in range(Q)]

work.sort()
ans = [-1] * Q
skip = [-1] * Q

for i in range(N):
	left = bisect.bisect_left(D, work[i][1])
	right = bisect.bisect_left(D, work[i][2])
	
	while left < right:
		if skip[left] == -1:
			skip[left] = right
			ans[left] = work[i][0]
			left += 1
		else:
			left = skip[left]					
		
for i in ans:
	print(i)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N, Q = map(int, input().split())
S, T, X = [0] * N, [0] * N, [0] * N

for i in range(N):
	S[i], T[i], X[i] = map(int, input().split())
	
D = [int(input()) for _ in range(Q)]

event = [] #工事と人を１つのリストで管理: (時間, 出来事の種類, [工事の位置])
#出来事の種類: (0: 工事の終了、1: 工事の開始、2: 人)
working = [] #現在行われている工事のリスト

for i in range(Q):
	event.append((D[i], 2))
	
for i in range(N):
	bisect.insort(event, (S[i] - X[i] - 0.5, 1, X[i]))
	bisect.insort(event, (T[i] - X[i] - 0.5, 0, X[i]))
	
for l in event:
	if l[1] == 1:
		bisect.insort(working, l[2])
	elif l[1] == 0:
		del working[bisect.bisect(working, l[2]) - 1]
	else:
		if len(working) > 0:
			print(working[0])
		else:
			print(-1)

Fixed submission:
import bisect
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N, Q = map(int, input().split())
S, T, X = [0] * N, [0] * N, [0] * N
work = []

for i in range(N):
	S[i], T[i], X[i] = map(int, input().split())
	work.append((X[i], S[i] - X[i], T[i] - X[i]))

D = [int(input()) for _ in range(Q)]

work.sort()
ans = [-1] * Q
skip = [-1] * Q

for i in range(N):
	left = bisect.bisect_left(D, work[i][1])
	right = bisect.bisect_left(D, work[i][2])
	
	while left < right:
		if skip[left] == -1:
			skip[left] = right
			ans[left] = work[i][0]
			left += 1
		else:
			left = skip[left]					
		
for i in ans:
	print(i)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N, Q = map(int, input().split())
S, T, X = [0] * N, [0] * N, [0] * N

for i in range(N):
	S[i], T[i], X[i] = map(int, input().split())
	
D = [int(input()) for _ in range(Q)]

event = [] #工事と人を１つのリストで管理: (時間, 出来事の種類, [工事の位置])
#出来事の種類: (0: 工事の終了、1: 工事の開始、2: 人)
working = [] #現在行われている工事のリスト

for i in range(Q):
	event.append((D[i], 2))
	
for i in range(N):
	bisect.insort(event, (S[i] - X[i] - 0.5, 1, X[i]))
	bisect.insort(event, (T[i] - X[i] - 0.5, 0, X[i]))
	
for l in event:
	if l[1] == 1:
		bisect.insort(working, l[2])
	elif l[1] == 0:
		del working[bisect.bisect(working, l[2]) - 1]
	else:
		if len(working) > 0:
			print(working[0])
		else:
			print(-1)

Fixed submission:
import bisect
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N, Q = map(int, input().split())
S, T, X = [0] * N, [0] * N, [0] * N
work = []

for i in range(N):
	S[i], T[i], X[i] = map(int, input().split())
	work.append((X[i], S[i] - X[i], T[i] - X[i]))

D = [int(input()) for _ in range(Q)]

work.sort()
ans = [-1] * Q
skip = [-1] * Q

for i in range(N):
	left = bisect.bisect_left(D, work[i][1])
	right = bisect.bisect_left(D, work[i][2])
	
	while left < right:
		if skip[left] == -1:
			skip[left] = right
			ans[left] = work[i][0]
			left += 1
		else:
			left = skip[left]					
		
for i in ans:
	print(i)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N, Q = map(int, input().split())
S = [0] * N
T = [0] * N
X = [0] * N
D = [0] * Q
event = []
working = []

for i in range(N):
	S[i], T[i], X[i] = map(int, input().split())
	event.append((S[i] - X[i], 1, X[i]))
	event.append((T[i] - X[i], -1, X[i]))
	
for i in range(Q):
	D[i] = int(input())
	
event.sort()
j = 0

for i in range(len(event)):		
	while event[i][0] > D[j] and j < Q:
		if len(working) > 0:
			print(min(working))
		else:
			print(-1)
		j += 1
	
	if event[i][1] == 1:
		working.append(event[i][2])
	else:
		working.remove(event[i][2])

while j < Q:
	print(-1)
	j += 1

Fixed submission:
import bisect
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N, Q = map(int, input().split())
S, T, X = [0] * N, [0] * N, [0] * N
work = []

for i in range(N):
	S[i], T[i], X[i] = map(int, input().split())
	work.append((X[i], S[i] - X[i], T[i] - X[i]))

D = [int(input()) for _ in range(Q)]

work.sort()
ans = [-1] * Q
skip = [-1] * Q

for i in range(N):
	left = bisect.bisect_left(D, work[i][1])
	right = bisect.bisect_left(D, work[i][2])
	
	while left < right:
		if skip[left] == -1:
			skip[left] = right
			ans[left] = work[i][0]
			left += 1
		else:
			left = skip[left]					
		
for i in ans:
	print(i)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N, Q = map(int, input().split())
S = [0] * N
T = [0] * N
X = [0] * N
D = [0] * Q
event = []
working = []
for i in range(N):
	S[i], T[i], X[i] = map(int, input().split())
	event.append((S[i] - X[i], 1, X[i]))
	event.append((T[i] - X[i], -1, X[i]))
	
for i in range(Q):
	D[i] = int(input())
	
event.sort()
j = 0
for i in range(len(event)):		
	while event[i][0] > D[j] and j < Q:
		if len(working) > 0:
			print(working[0])
		else:
			print(-1)
		j += 1
	
	if event[i][1] == 1:
		working.append(event[i][2])
	else:
		working.remove(event[i][2])

while j < Q:
	print(-1)
	j += 1

Fixed submission:
import bisect
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N, Q = map(int, input().split())
S, T, X = [0] * N, [0] * N, [0] * N
work = []

for i in range(N):
	S[i], T[i], X[i] = map(int, input().split())
	work.append((X[i], S[i] - X[i], T[i] - X[i]))

D = [int(input()) for _ in range(Q)]

work.sort()
ans = [-1] * Q
skip = [-1] * Q

for i in range(N):
	left = bisect.bisect_left(D, work[i][1])
	right = bisect.bisect_left(D, work[i][2])
	
	while left < right:
		if skip[left] == -1:
			skip[left] = right
			ans[left] = work[i][0]
			left += 1
		else:
			left = skip[left]					
		
for i in ans:
	print(i)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N, Q = map(int, input().split())
S = [0] * N
T = [0] * N
X = [0] * N
D = [0] * Q
event = []
working = []
for i in range(N):
	S[i], T[i], X[i] = map(int, input().split())
	event.append((S[i] - X[i], 1, X[i]))
	event.append((T[i] - X[i], -1, X[i]))
	
for i in range(Q):
	D[i] = int(input())
	
event.sort()
j = 0
for i in range(len(event)):		
	while event[i][0] > D[j] and j < Q:
		if len(working) > 0:
			print(min(working))
		else:
			print(-1)
		j += 1
	
	if event[i][1] == 1:
		working.append(event[i][2])
	else:
		working.remove(event[i][2])

while j < Q:
	print(-1)
	j += 1

Fixed submission:
import bisect
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N, Q = map(int, input().split())
S, T, X = [0] * N, [0] * N, [0] * N
work = []

for i in range(N):
	S[i], T[i], X[i] = map(int, input().split())
	work.append((X[i], S[i] - X[i], T[i] - X[i]))

D = [int(input()) for _ in range(Q)]

work.sort()
ans = [-1] * Q
skip = [-1] * Q

for i in range(N):
	left = bisect.bisect_left(D, work[i][1])
	right = bisect.bisect_left(D, work[i][2])
	
	while left < right:
		if skip[left] == -1:
			skip[left] = right
			ans[left] = work[i][0]
			left += 1
		else:
			left = skip[left]					
		
for i in ans:
	print(i)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N, Q = map(int, input().split())
S = [0] * N
T = [0] * N
X = [0] * N
D = [0] * Q
event = []
working = []
for i in range(N):
	S[i], T[i], X[i] = map(int, input().split())
	event.append((S[i] - X[i], 1, X[i]))
	event.append((T[i] - X[i], -1, X[i]))
	
for i in range(Q):
	D[i] = int(input())
	
event.sort()
j = 0
for i in range(len(event)):		
	while event[i][0] > D[j]:
		if len(working) > 0:
			print(min(working))
		else:
			print(-1)
		j += 1
	
	if event[i][1] == 1:
		working.append(event[i][2])
	else:
		working.remove(event[i][2])

while j < Q:
	print(-1)
	j += 1

Fixed submission:
import bisect
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N, Q = map(int, input().split())
S, T, X = [0] * N, [0] * N, [0] * N
work = []

for i in range(N):
	S[i], T[i], X[i] = map(int, input().split())
	work.append((X[i], S[i] - X[i], T[i] - X[i]))

D = [int(input()) for _ in range(Q)]

work.sort()
ans = [-1] * Q
skip = [-1] * Q

for i in range(N):
	left = bisect.bisect_left(D, work[i][1])
	right = bisect.bisect_left(D, work[i][2])
	
	while left < right:
		if skip[left] == -1:
			skip[left] = right
			ans[left] = work[i][0]
			left += 1
		else:
			left = skip[left]					
		
for i in ans:
	print(i)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N, Q = map(int, input().split())
S = [0] * N
T = [0] * N
X = [0] * N
D = [0] * Q
event = []
working = []
for i in range(N):
	S[i], T[i], X[i] = map(int, input().split())
	event.append((S[i] - X[i], 1, X[i]))
	event.append((T[i] - X[i], -1, X[i]))
	
for i in range(Q):
	D[i] = int(input())
	
event.sort()
j = 0
for i in range(len(event)):		
	while event[i][0] > D[j]:
		if len(working) > 0:
			print(min(working))
		else:
			print(-1)
		j += 1
	
	if event[i][1] == 1:
		working.append(event[i][2])
	else:
		working.remove(event[i][2])

while j < Q:
	print(-1)
	j += 1

Fixed submission:
import bisect
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N, Q = map(int, input().split())
S, T, X = [0] * N, [0] * N, [0] * N
work = []

for i in range(N):
	S[i], T[i], X[i] = map(int, input().split())
	work.append((X[i], S[i] - X[i], T[i] - X[i]))

D = [int(input()) for _ in range(Q)]

work.sort()
ans = [-1] * Q
skip = [-1] * Q

for i in range(N):
	left = bisect.bisect_left(D, work[i][1])
	right = bisect.bisect_left(D, work[i][2])
	
	while left < right:
		if skip[left] == -1:
			skip[left] = right
			ans[left] = work[i][0]
			left += 1
		else:
			left = skip[left]					
		
for i in ans:
	print(i)