Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.buffer.readline

N,Q = map(int, input().split())
List = []
dic = {}
for _ in range(N):
    s, t, x = map(int, input().split())
    List.append((s-0.5-x, 1, x)
    List.append((t-0.5-x, -1, x))
    dic[x] = False

import heapq
    
List.sort()

h = []
j = 0
for _ in range(Q):
    D = int(input())
    while j < 2*N and List[j][0] < D:
        if List[j][1] == 1:
            heapq.heappush(h, List[j][2])
            dic[List[j][2]] = True
        else:
            dic[List[j][2]] = False
        j += 1
    while h:
        ans = h[0]
        if dic[ans]:
            print(ans)
            break
        else:
            heapq.heappop(h)
    if not h:
        print(-1)

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

N,Q = map(int, input().split())
List = []
dic = {}
for _ in range(N):
    s, t, x = map(int, input().split())
    List.append((s-0.5-x, 1, x))
    List.append((t-0.5-x, -1, x))
    dic[x] = False

import heapq
    
List.sort()

h = []
j = 0
for _ in range(Q):
    D = int(input())
    while j < 2*N and List[j][0] < D:
        if List[j][1] == 1:
            heapq.heappush(h, List[j][2])
            dic[List[j][2]] = True
        else:
            dic[List[j][2]] = False
        j += 1
    while h:
        ans = h[0]
        if dic[ans]:
            print(ans)
            break
        else:
            heapq.heappop(h)
    if not h:
        print(-1)

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

N,Q = map(int, input().split())
List = []
dic = {}
for _ in range(N):
    s, t, x = map(int, input().split())
    List.append([s-0.5-x, 1, x])
    List.append([t-0.5-x, -1, x])
    dic[x] = False

import heapq
    
List.sort()

h = []
j = 0
for _ in range(Q):
    D = int(input())
    while j < 2*N and List[j][0] < D:
        if List[j][1] == 1:
            heapq.heappush(h, List[j][2])
            dic[List[j][2]] = True
        else:
            dic[List[j][2]] = False
        j += 1
    while h:
        ans = h[0]
        if dic[ans]:
            print(ans)
            break
        else:
            heapq.heappop(h)
    if not h:
        print(-1)

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

N,Q = map(int, input().split())
List = []
dic = {}
for _ in range(N):
    s, t, x = map(int, input().split())
    List.append((s-0.5-x, 1, x))
    List.append((t-0.5-x, -1, x))
    dic[x] = False

import heapq
    
List.sort()

h = []
j = 0
for _ in range(Q):
    D = int(input())
    while j < 2*N and List[j][0] < D:
        if List[j][1] == 1:
            heapq.heappush(h, List[j][2])
            dic[List[j][2]] = True
        else:
            dic[List[j][2]] = False
        j += 1
    while h:
        ans = h[0]
        if dic[ans]:
            print(ans)
            break
        else:
            heapq.heappop(h)
    if not h:
        print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
S = sys.stdin.readlines()

N,Q = map(int, S[0].split())
List = []
dic = {}
for i in S[1:N+1]:
    s, t, x = map(int, i.split())
    List.append([s-0.5-x, 1, x])
    List.append([t-0.5-x, -1, x])
    dic[x] = False
D = []
for i in S[N+1:]:
    D.append(int(i))

import heapq
    
List.sort()

h = []
j = 0
for i in range(Q):
    while j < 2*N and List[j][0] < D[i]:
        if List[j][1] == 1:
            heapq.heappush(h, List[j][2])
            dic[List[j][2]] = True
        else:
            dic[List[j][2]] = False
        j += 1
    while h:
        ans = h[0]
        if dic[ans]:
            print(ans)
            break
        else:
            heapq.heappop(h)
    if not h:
        print(-1)

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

N,Q = map(int, input().split())
List = []
dic = {}
for _ in range(N):
    s, t, x = map(int, input().split())
    List.append((s-0.5-x, 1, x))
    List.append((t-0.5-x, -1, x))
    dic[x] = False

import heapq
    
List.sort()

h = []
j = 0
for _ in range(Q):
    D = int(input())
    while j < 2*N and List[j][0] < D:
        if List[j][1] == 1:
            heapq.heappush(h, List[j][2])
            dic[List[j][2]] = True
        else:
            dic[List[j][2]] = False
        j += 1
    while h:
        ans = h[0]
        if dic[ans]:
            print(ans)
            break
        else:
            heapq.heappop(h)
    if not h:
        print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
S = sys.stdin.readlines()

N,Q = map(int, S[0].split())
List = []
dic = {}
for i in S[1:N+1]:
    s, t, x = map(int, i.split())
    List.append([s-0.5-x, 1, x])
    List.append([t-0.5-x, -1, x])
    dic[x] = False
D = []
for i in S[N+1:]:
    D.append(int(i))

import heapq
    
List.sort()

h = []
j = 0
for i in range(Q):
    while j < 2*N and List[j][0] < D[i]:
        if List[j][1] == 1:
            heapq.heappush(h, List[j][2])
            dic[List[j][2]] = True
        else:
            dic[List[j][2]] = False
        j += 1
    while h:
        ans = h[0]
        if dic[ans]:
            print(ans)
            break
        else:
            heapq.heappop(h)
    if not h:
        print(-1)

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

N,Q = map(int, input().split())
List = []
dic = {}
for _ in range(N):
    s, t, x = map(int, input().split())
    List.append((s-0.5-x, 1, x))
    List.append((t-0.5-x, -1, x))
    dic[x] = False

import heapq
    
List.sort()

h = []
j = 0
for _ in range(Q):
    D = int(input())
    while j < 2*N and List[j][0] < D:
        if List[j][1] == 1:
            heapq.heappush(h, List[j][2])
            dic[List[j][2]] = True
        else:
            dic[List[j][2]] = False
        j += 1
    while h:
        ans = h[0]
        if dic[ans]:
            print(ans)
            break
        else:
            heapq.heappop(h)
    if not h:
        print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
S = sys.stdin.readlines()

N,Q = map(int, S[0].split())
List = []
for i in S[1:N+1]:
    s, t, x = map(int, i.split())
    List.append([s-0.5-x, 1, x])
    List.append([t-0.5-x, -1, x])
D = []
for i in S[N+1:]:
    D.append(int(i))

import heapq
    
List.sort()

h_in = []
h_ex = []
ans = []
j = 0
for i in range(Q):
    while j < 2*N and List[j][0] < D[i]:
        if List[j][1] == 1:
            heapq.heappush(h_in, List[j][2])
        else:
            heapq.heappush(h_ex, List[j][2])
        j += 1
    while len(h_in) > 0 and len(h_ex) > 0 and h_in[0] == h_ex[0]:
        heapq.heappop(h_in)
        heapq.heappop(h_ex)
    if h_in:
        ans.append(h_in[0])
    else:
        ans.append(-1)
    
for i in range(Q):
    print(ans[i])

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

N,Q = map(int, input().split())
List = []
dic = {}
for _ in range(N):
    s, t, x = map(int, input().split())
    List.append((s-0.5-x, 1, x))
    List.append((t-0.5-x, -1, x))
    dic[x] = False

import heapq
    
List.sort()

h = []
j = 0
for _ in range(Q):
    D = int(input())
    while j < 2*N and List[j][0] < D:
        if List[j][1] == 1:
            heapq.heappush(h, List[j][2])
            dic[List[j][2]] = True
        else:
            dic[List[j][2]] = False
        j += 1
    while h:
        ans = h[0]
        if dic[ans]:
            print(ans)
            break
        else:
            heapq.heappop(h)
    if not h:
        print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
s = sys.stdin.readlines()

N,Q = map(int, s[0].split())
L = []
for i in s[1:N+1]:
    t = list(map(int, i.split()))
    L.append(t)
D = []
for i in s[N+1:]:
    D.append(int(i))

import heapq

List = []
for i in range(N):
    List.append([L[i][0]-0.5-L[i][2], 1, L[i][2]])
    List.append([L[i][1]-0.5-L[i][2], -1, L[i][2]])
    
List.sort()

h_in = []
h_ex = []
ans = []
j = 0
for i in range(Q):
    while j < 2*N and List[j][0] < D[i]:
        if List[j][1] == 1:
            heapq.heappush(h_in, List[j][2])
        else:
            heapq.heappush(h_ex, List[j][2])
        j += 1
    while len(h_in) > 0 and len(h_ex) > 0 and h_in[0] == h_ex[0]:
        heapq.heappop(h_in)
        heapq.heappop(h_ex)
    if h_in:
        ans.append(h_in[0])
    else:
        ans.append(-1)
    
for i in range(Q):
    print(ans[i])

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

N,Q = map(int, input().split())
List = []
dic = {}
for _ in range(N):
    s, t, x = map(int, input().split())
    List.append((s-0.5-x, 1, x))
    List.append((t-0.5-x, -1, x))
    dic[x] = False

import heapq
    
List.sort()

h = []
j = 0
for _ in range(Q):
    D = int(input())
    while j < 2*N and List[j][0] < D:
        if List[j][1] == 1:
            heapq.heappush(h, List[j][2])
            dic[List[j][2]] = True
        else:
            dic[List[j][2]] = False
        j += 1
    while h:
        ans = h[0]
        if dic[ans]:
            print(ans)
            break
        else:
            heapq.heappop(h)
    if not h:
        print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int, input().split())
L = [[int(l) for l in input().split()] for _ in range(N)]
D = [int(input()) for _ in range(Q)]

import heapq

List = []
for i in range(N):
    List.append([L[i][0]-0.5-L[i][2], 1, L[i][2]])
    List.append([L[i][1]-0.5-L[i][2], -1, L[i][2]])
    
List.sort()

h_in = []
h_ex = []
ans = []
j = 0
for i in range(Q):
    while j < 2*N and List[j][0] < D[i]:
        if List[j][1] == 1:
            heapq.heappush(h_in, List[j][2])
        else:
            heapq.heappush(h_ex, List[j][2])
        j += 1
    while len(h_in) > 0 and len(h_ex) > 0 and h_in[0] == h_ex[0]:
        heapq.heappop(h_in)
        heapq.heappop(h_ex)
    if h_in:
        ans.append(h_in[0])
    else:
        ans.append(-1)
    
for i in range(Q):
    print(ans[i])

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

N,Q = map(int, input().split())
List = []
dic = {}
for _ in range(N):
    s, t, x = map(int, input().split())
    List.append((s-0.5-x, 1, x))
    List.append((t-0.5-x, -1, x))
    dic[x] = False

import heapq
    
List.sort()

h = []
j = 0
for _ in range(Q):
    D = int(input())
    while j < 2*N and List[j][0] < D:
        if List[j][1] == 1:
            heapq.heappush(h, List[j][2])
            dic[List[j][2]] = True
        else:
            dic[List[j][2]] = False
        j += 1
    while h:
        ans = h[0]
        if dic[ans]:
            print(ans)
            break
        else:
            heapq.heappop(h)
    if not h:
        print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int, input().split())
L = [[int(l) for l in input().split()] for _ in range(N)]
D = [int(input()) for _ in range(Q)]

import heapq

List = []
for i in range(N):
    List.append([L[i][0]-0.5-L[i][2], 1, L[i][2]])
    List.append([L[i][1]-0.5-L[i][2], -1, L[i][2]])
    
List.sort()

h_in = []
h_ex = []
ans = []
j = 0
for i in range(Q):
    while j < 2*N and List[j][0] < D[i]:
        if List[j][1] == 1:
            heapq.heappush(h_in, List[j][2])
        else:
            heapq.heappush(h_ex, List[j][2])
        j += 1
    while len(h_in) > 0 and len(h_ex) > 0 and h_in[0] == h_ex[0]:
        heapq.heappop(h_in)
        heapq.heappop(h_ex)
    if h_in:
        ans.append(h_in[0])
    else:
        ans.append(-1)
    
for i in range(Q):
    print(ans[i])

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

N,Q = map(int, input().split())
List = []
dic = {}
for _ in range(N):
    s, t, x = map(int, input().split())
    List.append((s-0.5-x, 1, x))
    List.append((t-0.5-x, -1, x))
    dic[x] = False

import heapq
    
List.sort()

h = []
j = 0
for _ in range(Q):
    D = int(input())
    while j < 2*N and List[j][0] < D:
        if List[j][1] == 1:
            heapq.heappush(h, List[j][2])
            dic[List[j][2]] = True
        else:
            dic[List[j][2]] = False
        j += 1
    while h:
        ans = h[0]
        if dic[ans]:
            print(ans)
            break
        else:
            heapq.heappop(h)
    if not h:
        print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter
import bisect

N,Q = map(int, input().split())
L = [[int(l) for l in input().split()] for _ in range(N)]
D = [int(input()) for _ in range(Q)]

ans = [-1]*Q
L.sort(key=itemgetter(2))

K = []
for i in range(N):
    l = L[i][0]-0.5-L[i][2]
    r = L[i][1]-0.5-L[i][2]
    idx_l = bisect.bisect_left(D, l)
    idx_r = bisect.bisect_right(D, r)
    for j in range(len(K)):
        if idx_r < K[j][0]:
            K.append([idx_l, idx_r])
            break
        if idx_l <= K[j][0] < idx_r <= K[j][1]:
            idx_r = K[j][0]
            K[j][0] = idx_l
            break
        if K[j][0] <= idx_l <= K[j][1] <= idx_r:
            idx_l = K[j][1]
            K[j][1] = idx_r
            break
        if j == len(K)-1 and K[j][1] < idx_l:
            K.append([idx_l, idx_r-1])
    if i == 0:
        K.append([idx_l, idx_r-1])
    K.sort()
    for j in range(idx_l, idx_r):
        if ans[j] >= 0:
            continue
        ans[j] = L[i][2]
        
for i in range(Q):
    print(ans[i])

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

N,Q = map(int, input().split())
List = []
dic = {}
for _ in range(N):
    s, t, x = map(int, input().split())
    List.append((s-0.5-x, 1, x))
    List.append((t-0.5-x, -1, x))
    dic[x] = False

import heapq
    
List.sort()

h = []
j = 0
for _ in range(Q):
    D = int(input())
    while j < 2*N and List[j][0] < D:
        if List[j][1] == 1:
            heapq.heappush(h, List[j][2])
            dic[List[j][2]] = True
        else:
            dic[List[j][2]] = False
        j += 1
    while h:
        ans = h[0]
        if dic[ans]:
            print(ans)
            break
        else:
            heapq.heappop(h)
    if not h:
        print(-1)