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

n,q = map(int,input().split())
imos = []
for i in range(n):
    s,t,x = map(int,input().split())
    if t-x > 0:
        imos.append((max(s-x,0),x))
        imos.append((t-x,-x))
ans = set()
j = 0
l = len(imos)
imos.sort()
for i in range(q):
    d = int(input())
    while j < l:
        now,stop = imos[j]
        if now > d:
            break
        if stop > 0:
            ans.add(stop)
        else:
            ans.remove(-stop)
        j += 1
    if ans:
        print(min(ans))
    else:
        print(-1)


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

n,q = map(int,input().split())
imos = []
for i in range(n):
    s,t,x = map(int,input().split())
    imos.append((s-x,x))
    imos.append((t-x,-x))
ans = set()
j = 0
for i in range(q):
    d = int(input())
    imos.append((d,1e100))
imos.sort()
m = 1e100
flag = False
for t,stop in imos:
    if stop == 1e100:
        if ans:
            if not flag:
                m = min(ans)
                flag = True
            print(m)
        else:
            print(-1)
    elif stop > 0:
        ans.add(stop)
        if stop < m:
            m = stop
            flag = True
    else:
        ans.remove(-stop)
        if m == -stop:flag = False

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
imos = []
for i in range(n):
    s,t,x = map(int,input().split())
    imos.append((s-x,x))
    imos.append((t-x,-x))
ans = set()
j = 0
for i in range(q):
    d = int(input())
    imos.append((d,1e100))
imos.sort()
m = 1e100
flag = False
for t,stop in imos:
    if stop == 1e100:
        if ans:
            if not flag:
                m = min(ans)
                flag = True
            print(m)
        else:
            print(-1)
    elif stop > 0:
        ans.add(stop)
        if stop < m:m = stop
    else:
        ans.remove(-stop)
        if m == -stop:flag = False


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

n,q = map(int,input().split())
imos = []
for i in range(n):
    s,t,x = map(int,input().split())
    imos.append((s-x,x))
    imos.append((t-x,-x))
ans = set()
j = 0
for i in range(q):
    d = int(input())
    imos.append((d,1e100))
imos.sort()
m = 1e100
flag = False
for t,stop in imos:
    if stop == 1e100:
        if ans:
            if not flag:
                m = min(ans)
                flag = True
            print(m)
        else:
            print(-1)
    elif stop > 0:
        ans.add(stop)
        if stop < m:
            m = stop
            flag = True
    else:
        ans.remove(-stop)
        if m == -stop:flag = False

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
imos = []
for i in range(n):
    s,t,x = map(int,input().split())
    imos.append((s-x,x))
    imos.append((t-x,-x))
ans = set()
j = 0
for i in range(q):
    d = int(input())
    imos.append((d,1e100))
imos.sort()
for t,stop in imos:
    if stop == 1e100:
        if ans:
            print(min(ans))
        else:
            print(-1)
    elif stop > 0:
        ans.add(stop)
    else:
        ans.remove(-stop)


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

n,q = map(int,input().split())
imos = []
for i in range(n):
    s,t,x = map(int,input().split())
    imos.append((s-x,x))
    imos.append((t-x,-x))
ans = set()
j = 0
for i in range(q):
    d = int(input())
    imos.append((d,1e100))
imos.sort()
m = 1e100
flag = False
for t,stop in imos:
    if stop == 1e100:
        if ans:
            if not flag:
                m = min(ans)
                flag = True
            print(m)
        else:
            print(-1)
    elif stop > 0:
        ans.add(stop)
        if stop < m:
            m = stop
            flag = True
    else:
        ans.remove(-stop)
        if m == -stop:flag = False

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
imos = []
for i in range(n):
    s,t,x = map(int,input().split())
    imos.append((s-x,x))
    imos.append((t-x,-x))
ans = set()
j = 0
l = len(imos)
imos.sort()
for i in range(q):
    d = int(input())
    while j < l:
        now,stop = imos[j]
        if now > d:
            break
        if stop > 0:
            ans.add(stop)
        else:
            ans.remove(-stop)
        j += 1
    if ans:
        print(min(ans))
    else:
        print(-1)


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

n,q = map(int,input().split())
imos = []
for i in range(n):
    s,t,x = map(int,input().split())
    imos.append((s-x,x))
    imos.append((t-x,-x))
ans = set()
j = 0
for i in range(q):
    d = int(input())
    imos.append((d,1e100))
imos.sort()
m = 1e100
flag = False
for t,stop in imos:
    if stop == 1e100:
        if ans:
            if not flag:
                m = min(ans)
                flag = True
            print(m)
        else:
            print(-1)
    elif stop > 0:
        ans.add(stop)
        if stop < m:
            m = stop
            flag = True
    else:
        ans.remove(-stop)
        if m == -stop:flag = False

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
imos = []
for i in range(n):
    s,t,x = map(int,input().split())
    if t-x > 0:
        imos.append((max(s-x,0),x))
        imos.append((t-x,-x))
ans = set()
j = 0
l = len(imos)
imos.sort()
for i in range(q):
    d = int(input())
    while j < l:
        now,stop = imos[j]
        if now > d:
            break
        if stop > 0:
            ans.add(stop)
        else:
            ans.remove(-stop)
        j += 1
    if ans:
        print(min(ans))
    else:
        print(-1)


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

n,q = map(int,input().split())
imos = []
for i in range(n):
    s,t,x = map(int,input().split())
    imos.append((s-x,x))
    imos.append((t-x,-x))
ans = set()
j = 0
for i in range(q):
    d = int(input())
    imos.append((d,1e100))
imos.sort()
m = 1e100
flag = False
for t,stop in imos:
    if stop == 1e100:
        if ans:
            if not flag:
                m = min(ans)
                flag = True
            print(m)
        else:
            print(-1)
    elif stop > 0:
        ans.add(stop)
        if stop < m:
            m = stop
            flag = True
    else:
        ans.remove(-stop)
        if m == -stop:flag = False

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
imos = []
for i in range(n):
    s,t,x = map(int,input().split())
    if t-x > 0:
        imos.append((max(s-x,0),x))
        imos.append((t-x,-x))
ans = set()
j = 0
l = len(imos)
imos.sort()
for i in range(q):
    d = int(input())
    while j < l:
        now,stop = imos[j]
        if now > d:
            break
        if stop > 0:
            ans.add(stop)
        else:
            ans.remove(-stop)
        j += 1
    if ans:
        print(min(ans))
    else:
        print(-1)


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

n,q = map(int,input().split())
imos = []
for i in range(n):
    s,t,x = map(int,input().split())
    imos.append((s-x,x))
    imos.append((t-x,-x))
ans = set()
j = 0
for i in range(q):
    d = int(input())
    imos.append((d,1e100))
imos.sort()
m = 1e100
flag = False
for t,stop in imos:
    if stop == 1e100:
        if ans:
            if not flag:
                m = min(ans)
                flag = True
            print(m)
        else:
            print(-1)
    elif stop > 0:
        ans.add(stop)
        if stop < m:
            m = stop
            flag = True
    else:
        ans.remove(-stop)
        if m == -stop:flag = False

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n,q = map(int,input().split())
imos = []
heapq.heapify(imos)
for i in range(n):
    s,t,x = map(int,input().split())
    if t-x > 0:
        heapq.heappush(imos,(max(s-x,0),x))
        heapq.heappush(imos,(t-x,-x))
ans = set()
now = 0
for i in range(q):
    d = int(input())
    while imos:
        now,stop = heapq.heappop(imos)
        if now > d:
            heapq.heappush(imos,(now,stop))
            break
        if stop > 0:
            ans.add(stop)
        else:
            ans.remove(-stop)
    if ans:
        print(min(ans))
    else:
        print(-1)


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

n,q = map(int,input().split())
imos = []
for i in range(n):
    s,t,x = map(int,input().split())
    imos.append((s-x,x))
    imos.append((t-x,-x))
ans = set()
j = 0
for i in range(q):
    d = int(input())
    imos.append((d,1e100))
imos.sort()
m = 1e100
flag = False
for t,stop in imos:
    if stop == 1e100:
        if ans:
            if not flag:
                m = min(ans)
                flag = True
            print(m)
        else:
            print(-1)
    elif stop > 0:
        ans.add(stop)
        if stop < m:
            m = stop
            flag = True
    else:
        ans.remove(-stop)
        if m == -stop:flag = False

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n,q = map(int,input().split())
imos = []
heapq.heapify(imos)
for i in range(n):
    s,t,x = map(int,input().split())
    if t-x > 0:
        heapq.heappush(imos,(max(s-x,0),x))
        heapq.heappush(imos,(t-x,-x))
ans = set()
now = 0
for i in range(q):
    d = int(input())
    while imos:
        now,stop = heapq.heappop(imos)
        if now > d:
            heapq.heappush(imos,(now,stop))
            break
        if stop > 0:
            ans.add(stop)
        else:
            ans.remove(-stop)
    if ans:
        print(min(ans))
    else:
        print(-1)


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

n,q = map(int,input().split())
imos = []
for i in range(n):
    s,t,x = map(int,input().split())
    imos.append((s-x,x))
    imos.append((t-x,-x))
ans = set()
j = 0
for i in range(q):
    d = int(input())
    imos.append((d,1e100))
imos.sort()
m = 1e100
flag = False
for t,stop in imos:
    if stop == 1e100:
        if ans:
            if not flag:
                m = min(ans)
                flag = True
            print(m)
        else:
            print(-1)
    elif stop > 0:
        ans.add(stop)
        if stop < m:
            m = stop
            flag = True
    else:
        ans.remove(-stop)
        if m == -stop:flag = False