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

def BinarySearch(x,array):
    left=0
    right=len(array)-1

    while right-left>=0:
        mid=(left+right)//2
        if array[mid]==x:
            return mid
        elif array[mid]>x:
            right=mid-1
        else:
            left=mid+1
    return False


def main():
    ConstNum,PersonNum=map(int,input().split())

    S=[]
    T=[]
    X=[]
    for i in range(ConstNum):
        s,t,x=map(int,input().split())

        S.append(s-0.5)
        T.append(t-0.5)
        X.append(x)

    STX=zip(S,T,X)
    STX=sorted(STX)
    S,T,X=zip(*STX)

    S=deque(S)
    T=deque(T)
    X=deque(X)

    PersonsDistance=[]
    for i in range(PersonNum):
        d=int(input())
        PersonsDistance.insert(0,-1*d)

    res=[]

    time=0

    PersonsIndexes=[i for i in range(PersonNum-1,-1,-1)]

    while len(PersonsIndexes)>0 and len(X)>0:
        start=S.popleft()
        end=T.popleft()
        x=X.popleft()


        if start<time<end:
            underPerson=BinarySearch(x,PersonsDistance)
            if underPerson!=False:
                res.append((PersonsIndexes.pop(underPerson),PersonsDistance.pop(underPerson)))
            S.appendleft(start)
            T.appendleft(end)
            X.appendleft(x)
        elif start>time:
            S.appendleft(start)
            T.appendleft(end)
            X.appendleft(x)
        else:
            continue

        time+=1
        PersonsDistance=list(map(lambda x:x+1,PersonsDistance))

    for i in PersonsIndexes:
        res.append((i,-1))

    res=sorted(res)

    for i in res:
        print(i[1])

if __name__=="__main__":
    main()





Fixed submission:
from bisect import bisect_left

def main():
    ConstNum,PersonNum=map(int,input().split())

    S=[]
    T=[]
    X=[]
    for i in range(ConstNum):
        s,t,x=map(int,input().split())
        S.append(s)
        T.append(t)
        X.append(x)

    DepartureTime=[]
    for i in range(PersonNum):
        d=int(input())
        DepartureTime.append(d)

    XST=zip(X,S,T)
    XST=sorted(XST)

    res=[-1]*PersonNum
    stop=[-1]*PersonNum

    for x,s,t in XST:
        left_value=s-x
        right_value=t-x

        left_index=bisect_left(DepartureTime,left_value)
        right_index=bisect_left(DepartureTime,right_value)

        while left_index<right_index:
            if stop[left_index]==-1:
                res[left_index]=x
                stop[left_index]=right_index
                left_index+=1
            else:
                left_index=stop[left_index]

    for i in range(PersonNum):
        print(res[i])

if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    ConstNum,PersonNum=map(int,input().split())

    ConstInfo={}
    for i in range(ConstNum):
        S,T,X=map(int,input().split())

        if (X in ConstInfo):
            ConstInfo[X].append((S,T))
        else:
            ConstInfo[X]=[(S,T)]

        #ConstInfo=>{X:[(S,T),(S,T)],X:[(S,T)],...}

    ConstPlace=ConstInfo.keys()
    MaxConstPlace=max(ConstPlace)

    DepartureTime=[]
    for i in range(PersonNum):
        d=int(input())
        DepartureTime.append(d)

    res=[]

    for i in range(PersonNum):
        distance=0
        time=DepartureTime[i]

        underConst=False
        while distance<MaxConstPlace and underConst==False:
            time += 1
            distance += 1
            if (distance in ConstPlace):
                for const_time in ConstInfo[distance]:
                    if time>=const_time[0]-0.5 and time<=const_time[1]-0.5:
                        underConst=True
                        break



        if underConst:
            res.append(distance)
        else:
            res.append(-1)

    for i in res:
        print(i)

if __name__=="__main__":
    main()





Fixed submission:
from bisect import bisect_left

def main():
    ConstNum,PersonNum=map(int,input().split())

    S=[]
    T=[]
    X=[]
    for i in range(ConstNum):
        s,t,x=map(int,input().split())
        S.append(s)
        T.append(t)
        X.append(x)

    DepartureTime=[]
    for i in range(PersonNum):
        d=int(input())
        DepartureTime.append(d)

    XST=zip(X,S,T)
    XST=sorted(XST)

    res=[-1]*PersonNum
    stop=[-1]*PersonNum

    for x,s,t in XST:
        left_value=s-x
        right_value=t-x

        left_index=bisect_left(DepartureTime,left_value)
        right_index=bisect_left(DepartureTime,right_value)

        while left_index<right_index:
            if stop[left_index]==-1:
                res[left_index]=x
                stop[left_index]=right_index
                left_index+=1
            else:
                left_index=stop[left_index]

    for i in range(PersonNum):
        print(res[i])

if __name__=="__main__":
    main()