"""
愚直に一人一人交通止めに対してシミュレートしていは、絶対に間に合わない。

そこで、「この時間に出発したら"まず最初に"この通行止めで引っかかる」というのを前処理でまとめておく。
これは座標圧縮とセグメント木っぽいものを用いることで実現可能。
"""
N,Q = map(int,input().split())
STX = [list(map(int,input().split())) for _ in range(N)]
D = [int(input()) for _ in range(Q)]
times = set(D+[s-x for s,t,x in STX]+[t-x for s,t,x in STX])
compTimes = {t:i for i,t in enumerate(sorted(times))}

class originalSegTree:
    def __init__(self,n):
        self.end_leaves = 2**n.bit_length()
        self.tree = [float("INF")]*(2*self.end_leaves)
    
    def add(self,left,right,x):
        L = left + self.end_leaves
        R = right + self.end_leaves
        while L < R:
            if L&1:
                self.tree[L] = min(self.tree[L],x)
                L += 1
            if R&1:
                R -= 1
                self.tree[R] = min(self.tree[R],x)
            L >>= 1
            R >>= 1
    
    def merge(self):
        for i in range(1,self.end_leaves):
            self.tree[i*2] = min(self.tree[i],self.tree[i*2])
            self.tree[i*2+1] = min(self.tree[i],self.tree[i*2+1])

seg = originalSegTree(len(compTimes))
for s,t,x in STX:
    a = compTimes[s-x]
    b = compTimes[t-x]
    seg.add(a,b,x)

seg.merge()

for d in D:
    c = compTimes[d]
    ans = seg.tree[c+seg.end_leaves]
    if ans == float("INF"):
        ans = -1
    print(ans) """
愚直に一人一人交通止めに対してシミュレートしていは、絶対に間に合わない。

そこで、「この時間に出発したら"まず最初に"この通行止めで引っかかる」というのを前処理でまとめておく。
これは座標圧縮とセグメント木っぽいものを用いることで実現可能。
""" N,Q = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split Q list(map(int,input().split())) for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split STX = [list(map(int,input().split())) for _ in range(N)] STX [list(map(int,input().split())) for _ in range(N)] int(input()) for _ in range(Q) for _ in range(Q) _ range(Q) range Q for _ in range(Q) int(input()) int input() input D = [int(input()) for _ in range(Q)] D [int(input()) for _ in range(Q)] t-x for s,t,x in STX for s,t,x in STX s t x STX for s,t,x in STX t-x t x times = set(D+[s-x for s,t,x in STX]+[t-x for s,t,x in STX]) times set(D+[s-x for s,t,x in STX]+[t-x for s,t,x in STX]) set D+[s-x for s,t,x in STX]+[t-x for s,t,x in STX] D+[s-x for s,t,x in STX] D [s-x for s,t,x in STX] [t-x for s,t,x in STX] t:i for i,t in enumerate(sorted(times)) for i,t in enumerate(sorted(times)) i t enumerate(sorted(times)) enumerate sorted(times) sorted times for i,t in enumerate(sorted(times)) t i compTimes = {t:i for i,t in enumerate(sorted(times))} compTimes {t:i for i,t in enumerate(sorted(times))} class originalSegTree:
    def __init__(self,n):
        self.end_leaves = 2**n.bit_length()
        self.tree = [float("INF")]*(2*self.end_leaves)
    
    def add(self,left,right,x):
        L = left + self.end_leaves
        R = right + self.end_leaves
        while L < R:
            if L&1:
                self.tree[L] = min(self.tree[L],x)
                L += 1
            if R&1:
                R -= 1
                self.tree[R] = min(self.tree[R],x)
            L >>= 1
            R >>= 1
    
    def merge(self):
        for i in range(1,self.end_leaves):
            self.tree[i*2] = min(self.tree[i],self.tree[i*2])
            self.tree[i*2+1] = min(self.tree[i],self.tree[i*2+1]) originalSegTree def __init__(self,n):
        self.end_leaves = 2**n.bit_length()
        self.tree = [float("INF")]*(2*self.end_leaves)
    
     __init__ self.end_leaves = 2**n.bit_length() self.end_leaves self end_leaves 2**n.bit_length() 2 n.bit_length() n.bit_length n bit_length self.tree = [float("INF")]*(2*self.end_leaves) self.tree self tree [float("INF")]*(2*self.end_leaves) [float("INF")] float("INF") float "INF" 2*self.end_leaves 2 self.end_leaves self end_leaves self self n n def add(self,left,right,x):
        L = left + self.end_leaves
        R = right + self.end_leaves
        while L < R:
            if L&1:
                self.tree[L] = min(self.tree[L],x)
                L += 1
            if R&1:
                R -= 1
                self.tree[R] = min(self.tree[R],x)
            L >>= 1
            R >>= 1
    
     add L = left + self.end_leaves L left + self.end_leaves left self.end_leaves self end_leaves R = right + self.end_leaves R right + self.end_leaves right self.end_leaves self end_leaves while L < R:
            if L&1:
                self.tree[L] = min(self.tree[L],x)
                L += 1
            if R&1:
                R -= 1
                self.tree[R] = min(self.tree[R],x)
            L >>= 1
            R >>= 1
    
     L < R L R if L&1:
                self.tree[L] = min(self.tree[L],x)
                L += 1
             L&1 L 1 self.tree[L] = min(self.tree[L],x) self.tree[L] self.tree self tree L min(self.tree[L],x) min self.tree[L] self.tree self tree L x L += 1 L 1 if R&1:
                R -= 1
                self.tree[R] = min(self.tree[R],x)
             R&1 R 1 R -= 1 R 1 self.tree[R] = min(self.tree[R],x) self.tree[R] self.tree self tree R min(self.tree[R],x) min self.tree[R] self.tree self tree R x L >>= 1 L 1 R >>= 1 R 1 self self left left right right x x def merge(self):
        for i in range(1,self.end_leaves):
            self.tree[i*2] = min(self.tree[i],self.tree[i*2])
            self.tree[i*2+1] = min(self.tree[i],self.tree[i*2+1]) merge for i in range(1,self.end_leaves):
            self.tree[i*2] = min(self.tree[i],self.tree[i*2])
            self.tree[i*2+1] = min(self.tree[i],self.tree[i*2+1]) i range(1,self.end_leaves) range 1 self.end_leaves self end_leaves self.tree[i*2] = min(self.tree[i],self.tree[i*2]) self.tree[i*2] self.tree self tree i*2 i 2 min(self.tree[i],self.tree[i*2]) min self.tree[i] self.tree self tree i self.tree[i*2] self.tree self tree i*2 i 2 self.tree[i*2+1] = min(self.tree[i],self.tree[i*2+1]) self.tree[i*2+1] self.tree self tree i*2+1 i*2 i 2 1 min(self.tree[i],self.tree[i*2+1]) min self.tree[i] self.tree self tree i self.tree[i*2+1] self.tree self tree i*2+1 i*2 i 2 1 self self seg = originalSegTree(len(compTimes)) seg originalSegTree(len(compTimes)) originalSegTree len(compTimes) len compTimes for s,t,x in STX:
    a = compTimes[s-x]
    b = compTimes[t-x]
    seg.add(a,b,x) s t x STX a = compTimes[s-x] a compTimes[s-x] compTimes s-x s x b = compTimes[t-x] b compTimes[t-x] compTimes t-x t x seg.add(a,b,x) seg.add seg add a b x seg.merge() seg.merge seg merge for d in D:
    c = compTimes[d]
    ans = seg.tree[c+seg.end_leaves]
    if ans == float("INF"):
        ans = -1
    print(ans) d D c = compTimes[d] c compTimes[d] compTimes d ans = seg.tree[c+seg.end_leaves] ans seg.tree[c+seg.end_leaves] seg.tree seg tree c+seg.end_leaves c seg.end_leaves seg end_leaves if ans == float("INF"):
        ans = -1
     ans == float("INF") ans float("INF") float "INF" ans = -1 ans -1 print(ans) print ans c = compTimes[d] compTimes[d] c compTimes = {t:i for i,t in enumerate(sorted(times))} {t:i for i,t in enumerate(sorted(times))} compTimes Q = map(int,input().split()) map(int,input().split()) Q seg = originalSegTree(len(compTimes)) originalSegTree(len(compTimes)) seg ans = seg.tree[c+seg.end_leaves] seg.tree[c+seg.end_leaves] ans ans = -1 -1 ans a = compTimes[s-x] compTimes[s-x] a times = set(D+[s-x for s,t,x in STX]+[t-x for s,t,x in STX]) set(D+[s-x for s,t,x in STX]+[t-x for s,t,x in STX]) times STX = [list(map(int,input().split())) for _ in range(N)] [list(map(int,input().split())) for _ in range(N)] STX D = [int(input()) for _ in range(Q)] [int(input()) for _ in range(Q)] D N,Q = map(int,input().split()) map(int,input().split()) N class originalSegTree:
    def __init__(self,n):
        self.end_leaves = 2**n.bit_length()
        self.tree = [float("INF")]*(2*self.end_leaves)
    
    def add(self,left,right,x):
        L = left + self.end_leaves
        R = right + self.end_leaves
        while L < R:
            if L&1:
                self.tree[L] = min(self.tree[L],x)
                L += 1
            if R&1:
                R -= 1
                self.tree[R] = min(self.tree[R],x)
            L >>= 1
            R >>= 1
    
    def merge(self):
        for i in range(1,self.end_leaves):
            self.tree[i*2] = min(self.tree[i],self.tree[i*2])
            self.tree[i*2+1] = min(self.tree[i],self.tree[i*2+1]) class originalSegTree:
    def __init__(self,n):
        self.end_leaves = 2**n.bit_length()
        self.tree = [float("INF")]*(2*self.end_leaves)
    
    def add(self,left,right,x):
        L = left + self.end_leaves
        R = right + self.end_leaves
        while L < R:
            if L&1:
                self.tree[L] = min(self.tree[L],x)
                L += 1
            if R&1:
                R -= 1
                self.tree[R] = min(self.tree[R],x)
            L >>= 1
            R >>= 1
    
    def merge(self):
        for i in range(1,self.end_leaves):
            self.tree[i*2] = min(self.tree[i],self.tree[i*2])
            self.tree[i*2+1] = min(self.tree[i],self.tree[i*2+1]) originalSegTree b = compTimes[t-x] compTimes[t-x] b
"""
愚直に一人一人交通止めに対してシミュレートしていは、絶対に間に合わない。

そこで、「この時間に出発したら"まず最初に"この通行止めで引っかかる」というのを前処理でまとめておく。
これは座標圧縮とセグメント木っぽいものを用いることで実現可能。
"""
N,Q = map(int,input().split())
STX = [list(map(int,input().split())) for _ in range(N)]
D = [int(input()) for _ in range(Q)]
times = set(D+[s-x for s,t,x in STX]+[t-x for s,t,x in STX])
compTimes = {t:i for i,t in enumerate(sorted(times))}

class originalSegTree:
    def __init__(self,n):
        self.end_leaves = 2**n.bit_length()
        self.tree = [float("INF")]*(2*self.end_leaves)
    
    def add(self,left,right,x):
        L = left + self.end_leaves
        R = right + self.end_leaves
        while L < R:
            if L&1:
                self.tree[L] = min(self.tree[L],x)
                L += 1
            if R&1:
                R -= 1
                self.tree[R] = min(self.tree[R],x)
            L >>= 1
            R >>= 1
    
    def merge(self):
        for i in range(1,self.end_leaves):
            self.tree[i*2] = min(self.tree[i],self.tree[i*2])
            self.tree[i*2+1] = min(self.tree[i],self.tree[i*2+1])

seg = originalSegTree(len(compTimes))
for s,t,x in STX:
    a = compTimes[s-x]
    b = compTimes[t-x]
    seg.add(a,b,x)

seg.merge()

for d in D:
    c = compTimes[d]
    ans = seg.tree[c+seg.end_leaves]
    if ans == float("INF"):
        ans = -1
    print(ans)
