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

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

ans=[-1]*Q
for X,S,T in XST:
    s,t=S-X,T-X
    left=bisect(D,[s])
    right=bisect(D,[t])
    
    for i in range(left,right):
        ans[D[i][1]]=X
    D=D[:left]+D[right:]
    
for u in ans:
    print(u)

Fixed submission:
from bisect import bisect,bisect_left
import sys
input=sys.stdin.readline

def main():
    n,q=map(int,input().split())
    xst=[]
    for i in range(n):
        s,t,x=map(int,input().split())
        xst.append([x,s-x,t-x])
    xst.sort()
    d=[None]*q
    for i in range(q):
        d[i]=int(input())
    ans=[-1]*q
    skip=[-1]*q
    for u in xst:
        x ,left ,right = u
        a=bisect_left(d,left)
        b=bisect_left(d,right)
        while a < b:
            if skip[a] == -1:
                ans[a]=x
                skip[a]=b
                a+=1
            else:
                a=skip[a]
    for u in ans:
        print(u)

if __name__=="__main__":
    main()

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

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

ans=[-1]*Q
for X,S,T in XST:
    s,t=S-X,T-X
    left=bisect(D,[s])
    right=bisect(D,[t])
    
    for i in range(left,right):
        ans[D[i][1]]=X
    D=D[:left]+D[right:]
    
for u in ans:
    print(u)

Fixed submission:
from bisect import bisect,bisect_left
import sys
input=sys.stdin.readline

def main():
    n,q=map(int,input().split())
    xst=[]
    for i in range(n):
        s,t,x=map(int,input().split())
        xst.append([x,s-x,t-x])
    xst.sort()
    d=[None]*q
    for i in range(q):
        d[i]=int(input())
    ans=[-1]*q
    skip=[-1]*q
    for u in xst:
        x ,left ,right = u
        a=bisect_left(d,left)
        b=bisect_left(d,right)
        while a < b:
            if skip[a] == -1:
                ans[a]=x
                skip[a]=b
                a+=1
            else:
                a=skip[a]
    for u in ans:
        print(u)

if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect,bisect_left
import sys
import itertools
input=sys.stdin.readline

def main():
    n,q=map(int,input().split())
    xst=[]
    for i in range(n):
        s,t,x=map(int,input().split())
        xst.append([x,s,t])
    xst.sort()
    d=[None]*q
    for i in range(q):
        d[i]=[int(input()),i]
    ans=[-1]*q
    for u in xst:
        x,s,t=u
        left=s-x
        right=t-x-1
        a=bisect(d,[left])
        b=bisect(d,[right,q+1])
        for u in d[a:b]:
            ans[u[1]]=x
        d=list(itertools.chain(d[:a],d[b:]))
    for u in ans:
        print(u)

if __name__=="__main__":
    main()

Fixed submission:
from bisect import bisect,bisect_left
import sys
input=sys.stdin.readline

def main():
    n,q=map(int,input().split())
    xst=[]
    for i in range(n):
        s,t,x=map(int,input().split())
        xst.append([x,s-x,t-x])
    xst.sort()
    d=[None]*q
    for i in range(q):
        d[i]=int(input())
    ans=[-1]*q
    skip=[-1]*q
    for u in xst:
        x ,left ,right = u
        a=bisect_left(d,left)
        b=bisect_left(d,right)
        while a < b:
            if skip[a] == -1:
                ans[a]=x
                skip[a]=b
                a+=1
            else:
                a=skip[a]
    for u in ans:
        print(u)

if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect,bisect_left
import sys
import itertools
input=sys.stdin.readline

def main():
    n,q=map(int,input().split())
    xst=[]
    for i in range(n):
        s,t,x=map(int,input().split())
        xst.append([x,s,t])
    xst.sort()
    d=[None]*q
    for i in range(q):
        d[i]=[int(input()),i]
    ans=[-1]*q
    for u in xst:
        x,s,t=u
        left=s-x
        right=t-x-1
        a=bisect(d,[left])
        b=bisect(d,[right,q+1])
        for u in d[a:b]:
            ans[u[1]]=x
        d=list(itertools.chain(d[:a],d[b:]))
    for u in ans:
        print(u)

if __name__=="__main__":
    main()

Fixed submission:
from bisect import bisect,bisect_left
import sys
input=sys.stdin.readline

def main():
    n,q=map(int,input().split())
    xst=[]
    for i in range(n):
        s,t,x=map(int,input().split())
        xst.append([x,s-x,t-x])
    xst.sort()
    d=[None]*q
    for i in range(q):
        d[i]=int(input())
    ans=[-1]*q
    skip=[-1]*q
    for u in xst:
        x ,left ,right = u
        a=bisect_left(d,left)
        b=bisect_left(d,right)
        while a < b:
            if skip[a] == -1:
                ans[a]=x
                skip[a]=b
                a+=1
            else:
                a=skip[a]
    for u in ans:
        print(u)

if __name__=="__main__":
    main()

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

def main():
    n,q=map(int,input().split())
    xst=[]
    for i in range(n):
        s,t,x=map(int,input().split())
        xst.append([x,s,t])
    xst.sort()
    d=[None]*q
    for i in range(q):
        d[i]=[int(input()),i]
    ans=[-1]*q
    for u in xst:
        x,s,t=u
        left=s-x
        right=t-x-1
        a=bisect(d,[left])
        b=bisect(d,[right,q+1])
        for u in d[a:b]:
            ans[u[1]]=x
        d=d[:a]+d[b:]
    for u in ans:
        print(u)

if __name__=="__main__":
    main()

Fixed submission:
from bisect import bisect,bisect_left
import sys
input=sys.stdin.readline

def main():
    n,q=map(int,input().split())
    xst=[]
    for i in range(n):
        s,t,x=map(int,input().split())
        xst.append([x,s-x,t-x])
    xst.sort()
    d=[None]*q
    for i in range(q):
        d[i]=int(input())
    ans=[-1]*q
    skip=[-1]*q
    for u in xst:
        x ,left ,right = u
        a=bisect_left(d,left)
        b=bisect_left(d,right)
        while a < b:
            if skip[a] == -1:
                ans[a]=x
                skip[a]=b
                a+=1
            else:
                a=skip[a]
    for u in ans:
        print(u)

if __name__=="__main__":
    main()

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

def main():
    n,q=map(int,input().split())
    xst=[]
    for i in range(n):
        s,t,x=map(int,input().split())
        xst.append([x,s,t])
    xst.sort()
    d=[None]*q
    for i in range(q):
        d[i]=[int(input()),i]
    ans=[-1]*q
    for u in xst:
        x,s,t=u
        left=s-x
        right=t-x-1
        a=bisect(d,[left])
        b=bisect(d,[right,q+1])
        for u in d[a:b]:
            ans[u[1]]=x
        d=d[:a]+d[b:]
    for u in ans:
        print(u)

if __name__=="__main__":
    main()

Fixed submission:
from bisect import bisect,bisect_left
import sys
input=sys.stdin.readline

def main():
    n,q=map(int,input().split())
    xst=[]
    for i in range(n):
        s,t,x=map(int,input().split())
        xst.append([x,s-x,t-x])
    xst.sort()
    d=[None]*q
    for i in range(q):
        d[i]=int(input())
    ans=[-1]*q
    skip=[-1]*q
    for u in xst:
        x ,left ,right = u
        a=bisect_left(d,left)
        b=bisect_left(d,right)
        while a < b:
            if skip[a] == -1:
                ans[a]=x
                skip[a]=b
                a+=1
            else:
                a=skip[a]
    for u in ans:
        print(u)

if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect,bisect_left
n,q=map(int,input().split())
xst=[]
for i in range(n):
    s,t,x=map(int,input().split())
    xst.append([x,s,t])
xst.sort()
d=[]
for i in range(q):
    D=int(input())
    d.append([D,i])
ans=[-1]*q
for u in xst:
    x,s,t=u
    left=s-x
    right=t-x-1
    a=bisect(d,[left])
    b=bisect(d,[right,q+1])
    for u in d[a:b]:
        ans[u[1]]=x
    d=d[:a]+d[b:]
for u in ans:
    print(u)

Fixed submission:
from bisect import bisect,bisect_left
import sys
input=sys.stdin.readline

def main():
    n,q=map(int,input().split())
    xst=[]
    for i in range(n):
        s,t,x=map(int,input().split())
        xst.append([x,s-x,t-x])
    xst.sort()
    d=[None]*q
    for i in range(q):
        d[i]=int(input())
    ans=[-1]*q
    skip=[-1]*q
    for u in xst:
        x ,left ,right = u
        a=bisect_left(d,left)
        b=bisect_left(d,right)
        while a < b:
            if skip[a] == -1:
                ans[a]=x
                skip[a]=b
                a+=1
            else:
                a=skip[a]
    for u in ans:
        print(u)

if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect,bisect_left
n,q=map(int,input().split())
xst=[]
for i in range(n):
    s,t,x=map(int,input().split())
    xst.append([x,s,t])
xst.sort()
d=[]
for i in range(q):
    D=int(input())
    d.append([D,i])
ans=[-1]*q
for u in xst:
    x,s,t=u
    left=s-x
    right=t-x-1
    a=bisect(d,[left])
    b=bisect(d,[right,q+1])
    for u in d[a:b]:
        ans[u[1]]=x
    d=d[:a]+d[b:]
for u in ans:
    print(u)

Fixed submission:
from bisect import bisect,bisect_left
import sys
input=sys.stdin.readline

def main():
    n,q=map(int,input().split())
    xst=[]
    for i in range(n):
        s,t,x=map(int,input().split())
        xst.append([x,s-x,t-x])
    xst.sort()
    d=[None]*q
    for i in range(q):
        d[i]=int(input())
    ans=[-1]*q
    skip=[-1]*q
    for u in xst:
        x ,left ,right = u
        a=bisect_left(d,left)
        b=bisect_left(d,right)
        while a < b:
            if skip[a] == -1:
                ans[a]=x
                skip[a]=b
                a+=1
            else:
                a=skip[a]
    for u in ans:
        print(u)

if __name__=="__main__":
    main()