Buggy python submission (verdict: Runtime Error):
from heapq import heappush, heappop
import sys

ans = [None]*Q
def solve():
    readline = sys.stdin.readline
    N, Q = map(int, readline().split())
    qs = [0]*(N+1)
    for i in range(N):
        s, t, x = map(int, readline().split())
        qs[i] = (s-x, t-x, x)
    qs[N] = (10**10, 10**10, 0)
    qs.sort()

    que = []
    D = [int(readline()) for i in range(Q)]
    j = 0
    it = iter(qs).__next__
    s, t, x = it()
    v = w = N
    for d in D:
        while j < N and s <= d:
            heappush(que, (x, t))
            v, w = que[0]
            s, t, x = it()
        while que and w <= d:
            heappop(que)
            if que:
                v, w = que[0]
        if que:
            yield "%d\n" % v
        else:
            yield "-1\n"
ans[:] = solve()
sys.stdout.writelines(ans)

Fixed submission:
from heapq import heappush, heappop
import sys
from __pypy__ import builders
readline = sys.stdin.readline
N, Q = map(int, readline().split())
qs = [0]*N
for i in range(N):
    s, t, x = map(int, readline().split())
    qs[i] = (s-x, t-x, x)
qs.sort()

b = builders.StringBuilder(Q)
que = []
D = [int(readline()) for i in range(Q)]
j = 0
for d in D:
    while j < N and qs[j][0] <= d:
        s, t, x = qs[j]
        heappush(que, (x, t))
        j += 1
    while que and que[0][1] <= d:
        heappop(que)
    if que:
        b.append("%d\n" % que[0][0])
    else:
        b.append("-1\n")
sys.stdout.write(b.build())

Buggy python submission (verdict: Runtime Error):
from heapq import heappush, heappop
import sys, os
from __pypy__ import builders
readline = sys.stdin.readline
N, Q = map(int, readline().split())
qs = [0]*N
for i in range(N):
    s, t, x = map(int, readline().split())
    qs[i] = (s-x, t-x, x)
qs.sort()

b = builders.BytesBuilder(Q)
que = []
D = [int(readline()) for i in range(Q)]
j = 0
for d in D:
    while j < N and qs[j][0] <= d:
        s, t, x = qs[j]
        heappush(que, (x, t))
        j += 1
    while que and que[0][1] <= d:
        heappop(que)
    if que:
        b.append(b"%d\n" % que[0][0])
    else:
        b.append(b"-1\n")
os.write(1, b.build())

Fixed submission:
from heapq import heappush, heappop
import sys
from __pypy__ import builders
readline = sys.stdin.readline
N, Q = map(int, readline().split())
qs = [0]*N
for i in range(N):
    s, t, x = map(int, readline().split())
    qs[i] = (s-x, t-x, x)
qs.sort()

b = builders.StringBuilder(Q)
que = []
D = [int(readline()) for i in range(Q)]
j = 0
for d in D:
    while j < N and qs[j][0] <= d:
        s, t, x = qs[j]
        heappush(que, (x, t))
        j += 1
    while que and que[0][1] <= d:
        heappop(que)
    if que:
        b.append("%d\n" % que[0][0])
    else:
        b.append("-1\n")
sys.stdout.write(b.build())

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop
import sys
from __pypy__ import builders
readline = sys.stdin.readline
N, Q = map(int, readline().split())
U = [0]*N
qs = []
for i in range(N):
    s, t, x = map(int, readline().split())
    qs.append((s-x, x, i, 1))
    qs.append((t-x, x, i, 0))
qs.sort()

b = builders.StringBuilder(Q)
que = []
j = 0
for i in range(Q):
    d = int(readline())
    while j < 2*N and qs[j][0] <= d:
        _, x, i, m = qs[j]
        if m:
            heappush(que, (x, i))
        else:
            U[i] = 1
        j += 1
    while que and U[que[0][1]]:
        heappop(que)
    if que:
        b.append("%d\n" % que[0][0])
    else:
        b.append("-1\n")
sys.stdout.write(b.build())

Fixed submission:
from heapq import heappush, heappop
import sys
from __pypy__ import builders
readline = sys.stdin.readline
N, Q = map(int, readline().split())
qs = [0]*N
for i in range(N):
    s, t, x = map(int, readline().split())
    qs[i] = (s-x, t-x, x)
qs.sort()

b = builders.StringBuilder(Q)
que = []
D = [int(readline()) for i in range(Q)]
j = 0
for d in D:
    while j < N and qs[j][0] <= d:
        s, t, x = qs[j]
        heappush(que, (x, t))
        j += 1
    while que and que[0][1] <= d:
        heappop(que)
    if que:
        b.append("%d\n" % que[0][0])
    else:
        b.append("-1\n")
sys.stdout.write(b.build())

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop
import sys
from __pypy__ import builders
readline = sys.stdin.readline
N, Q = map(int, readline().split())
U = [0]*N
qs = []
for i in range(N):
    s, t, x = map(int, input().split())
    qs.append((s-x, x, i, 1))
    qs.append((t-x, x, i, 0))
qs.sort()

b = builders.StringBuilder(Q)
que = []
j = 0
for i in range(Q):
    d = int(input())
    while j < 2*N and qs[j][0] <= d:
        _, x, i, m = qs[j]
        if m:
            heappush(que, (x, i))
        else:
            U[i] = 1
        j += 1
    while que and U[que[0][1]]:
        heappop(que)
    if que:
        b.append("%d\n" % que[0][0])
    else:
        b.append("-1\n")
sys.stdout.write(b.build())

Fixed submission:
from heapq import heappush, heappop
import sys
from __pypy__ import builders
readline = sys.stdin.readline
N, Q = map(int, readline().split())
qs = [0]*N
for i in range(N):
    s, t, x = map(int, readline().split())
    qs[i] = (s-x, t-x, x)
qs.sort()

b = builders.StringBuilder(Q)
que = []
D = [int(readline()) for i in range(Q)]
j = 0
for d in D:
    while j < N and qs[j][0] <= d:
        s, t, x = qs[j]
        heappush(que, (x, t))
        j += 1
    while que and que[0][1] <= d:
        heappop(que)
    if que:
        b.append("%d\n" % que[0][0])
    else:
        b.append("-1\n")
sys.stdout.write(b.build())

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from __pypy__ import builders
readline = sys.stdin.readline
N, Q = map(int, readline().split())

data = [0]*(N+2)
def add(k, x):
    while k <= N:
        data[k] += x
        k += k & -k
N0 = 2**(N-1).bit_length()
def lower_bound(x):
    w = i = 0
    k = N0
    while k:
        if i+k <= N+1 and w + data[i+k] <= x:
            w += data[i+k]
            i += k
        k >>= 1
    return i+1

P = [list(map(int, readline().split())) for i in range(N)]
*S, = set(x for s, t, x in P)
S.sort()
mp = {e: i for i, e in enumerate(S)}
D = [int(readline()) for i in range(Q)]
que = []
for s, t, x in P:
    y = mp[x]
    que.append((s-x, y, 1))
    que.append((t-x, y, -1))
que.sort()
b = builders.StringBuilder(Q)
i = 0
for d in D:
    while i < 2*N and que[i][0] <= d:
        _, j, f = que[i]
        add(j+1, f)
        i += 1
    k = lower_bound(0)
    if k == N+2:
        b.append("-1\n")
    else:
        b.append("%d\n" % S[k-1])
sys.stdout.write(b.build())

Fixed submission:
from heapq import heappush, heappop
import sys
from __pypy__ import builders
readline = sys.stdin.readline
N, Q = map(int, readline().split())
qs = [0]*N
for i in range(N):
    s, t, x = map(int, readline().split())
    qs[i] = (s-x, t-x, x)
qs.sort()

b = builders.StringBuilder(Q)
que = []
D = [int(readline()) for i in range(Q)]
j = 0
for d in D:
    while j < N and qs[j][0] <= d:
        s, t, x = qs[j]
        heappush(que, (x, t))
        j += 1
    while que and que[0][1] <= d:
        heappop(que)
    if que:
        b.append("%d\n" % que[0][0])
    else:
        b.append("-1\n")
sys.stdout.write(b.build())

Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline
N, Q = map(int, readline().split())

data = [0]*(N+2)
def add(k, x):
    while k <= N:
        data[k] += x
        k += k & -k
def get(k):
    s = 0
    while k > 0:
        s += data[k]
        k -= k & -k
    return s
N0 = 2**(N-1).bit_length()
def lower_bound(x):
    w = i = 0
    k = N0
    while k:
        if i+k <= N+1 and w + data[i+k] <= x:
            w += data[i+k]
            i += k
        k >>= 1
    return i+1

P = [list(map(int, readline().split())) for i in range(N)]
S = sorted(set(x for s, t, x in P))
mp = {e: i for i, e in enumerate(S)}
D = [int(readline()) for i in range(Q)]
que = []
for s, t, x in P:
    y = mp[x]
    que.append((s-x, y, 1))
    que.append((t-x, y, -1))
que.sort()
ans = []
i = 0
for d in D:
    while i < 2*N and que[i][0] <= d:
        _, j, f = que[i]
        add(j+1, f)
        i += 1
    k = lower_bound(0)
    if k == N+2:
        ans.append("-1\n")
    else:
        ans.append("%d\n" % S[k-1])
sys.stdout.writelines(ans)

Fixed submission:
from heapq import heappush, heappop
import sys
from __pypy__ import builders
readline = sys.stdin.readline
N, Q = map(int, readline().split())
qs = [0]*N
for i in range(N):
    s, t, x = map(int, readline().split())
    qs[i] = (s-x, t-x, x)
qs.sort()

b = builders.StringBuilder(Q)
que = []
D = [int(readline()) for i in range(Q)]
j = 0
for d in D:
    while j < N and qs[j][0] <= d:
        s, t, x = qs[j]
        heappush(que, (x, t))
        j += 1
    while que and que[0][1] <= d:
        heappop(que)
    if que:
        b.append("%d\n" % que[0][0])
    else:
        b.append("-1\n")
sys.stdout.write(b.build())