Problem p03033 (python)

Fixed submission:
# coding: utf-8
import re
import math
import fractions
import random
import heapq
import time
import sys
input = sys.stdin.readline
#import numpy as np
mod=int(10**9+7)
inf=int(10**20)
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def comb(n,r):return math.factorial(n)//math.factorial(n-r)//math.factorial(r)
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
 
 
#main
N,Q=map(int,input().split())
E=[]
for a in range(N):
    s,t,x=map(int,input().split())
    E.append([s-x-0.5,1,x])
    E.append([t-x-0.5,-1,x])

for a in range(Q):
    E.append([int(input()),0,0])
E.sort(key=lambda x:x[0])
 
S=set()
H=[]
for time_,type_,x in E:
    if type_==1:
        S.add(x)
        heapq.heappush(H,x)
    elif type_==-1:
        if(x in S):S.remove(x)
    else:
        while H and H[0] not in S:
            heapq.heappop(H)
        print(H[0] if H else -1)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import re
import math
import fractions
import random
from heapq import heappop,heappush
import time
import sys
input = sys.stdin.readline
#import numpy as np
mod=int(10**9+7)
inf=int(10**20)
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def comb(n,r):return math.factorial(n)//math.factorial(n-r)//math.factorial(r)
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
 
 
#main
N,Q=map(int,input().split())
E=[]
for a in range(N):
    s,t,x=map(int,input().split())
    E.append((s-x,1,x))
    E.append((t-x,-1,x))

for a in range(Q):
    E.append((int(input()),2,0))
E.sort()
 
S=set()
H=[]
for time_,type_,x in E:
    if type_:
        S.add(x)
        heapq.heappush(H,x)
    elif type_==-1:
        S.remove(x)
    else:
        while H and H[0] not in S:
            heapq.heappop(H)
        print(H[0] if H else -1)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import re
import math
import fractions
import random
import heapq
import time
import sys
input = sys.stdin.readline
#import numpy as np
mod=int(10**9+7)
inf=int(10**20)
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def comb(n,r):return math.factorial(n)//math.factorial(n-r)//math.factorial(r)
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
 
 
#main
N,Q=map(int,input().split())
E=[]
for a in range(N):
    s,t,x=map(int,input().split())
    E.append([s-x-0.5,1,x])
    E.append([t-x-0.5,2,x])

for a in range(Q):
    E.append([int(input()),0,0])
E.sort(key=lambda x:x[0])
 
S=set()
H=[]
for time_,type_,x in E:
    if type_==1:
        S.add(x)
        heapq.heappush(H,x)
    elif type_==2:
        S.remove(x)
    else:
        while H and H[0] not in S:
            heapq.heappop(H)
        print(H[0] if H else -1)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import re
import math
import fractions
import random
import heapq
import time
import sys
input = sys.stdin.readline
#import numpy as np
mod=int(10**9+7)
inf=int(10**20)
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def comb(n,r):return math.factorial(n)//math.factorial(n-r)//math.factorial(r)
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
 
 
#main
N,Q=map(int,input().split())
E=[]
for a in range(N):
    s,t,x=map(int,input().split())
    E.append([s-x-0.5,1,x])
    E.append([t-x-0.5,-1,x])

for a in range(Q):
    E.append([int(input()),0,0])
E.sort(key=lambda x:x[0])
 
S=set()
H=[]
for time_,type_,x in E:
    if type_==1:
        S.add(x)
    elif type_==-1:
        S.remove(x)
    else:
        print(-1)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import re
import math
import fractions
import random
import heapq
import time
import sys
input = sys.stdin.readline
#import numpy as np
mod=int(10**9+7)
inf=int(10**20)
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def comb(n,r):return math.factorial(n)//math.factorial(n-r)//math.factorial(r)
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
 
 
#main
N,Q=map(int,input().split())
E=[]
for a in range(N):
    s,t,x=map(int,input().split())
    E.append([s-x-0.5,1,x])
    E.append([t-x-0.5,-1,x])

for a in range(Q):
    E.append([int(input()),0,0])
E.sort(key=lambda x:x[0])
 
S=set()
H=[]
for time_,type_,x in E:
    if type_==1:
        S.add(x)
    elif type_==-1:
        S.remove(x)
    else:
        print(H[0] if H else -1)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import re
import math
import fractions
import random
import heapq
import time
import sys
input = sys.stdin.readline
#import numpy as np
mod=int(10**9+7)
inf=int(10**20)
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def comb(n,r):return math.factorial(n)//math.factorial(n-r)//math.factorial(r)
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
 
 
#main
N,Q=map(int,input().split())
E=[]
for a in range(N):
    s,t,x=map(int,input().split())
    E.append([s-x-0.5,1,x])
    E.append([t-x-0.5,-1,x])

for a in range(Q):
    E.append([int(input()),0,0])
E.sort(key=lambda x:x[0])
 
S=set()
H=[]
for time_,type_,x in E:
    if type_==1:
        S.add(x)
        heapq.heappush(H,x)
    elif type_==-1:
        S.remove(x)
    else:
        while H and H[0] not in S:
            heapq.heappop(H)
        #print(H[0] if H else -1)
        print(4723947284234)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import re
import math
import fractions
import random
import heapq
import time
import sys
input = sys.stdin.readline
#import numpy as np
mod=int(10**9+7)
inf=int(10**20)
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def comb(n,r):return math.factorial(n)//math.factorial(n-r)//math.factorial(r)
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
 
 
#main
N,Q=map(int,input().split())
E=[]
for a in range(N):
    s,t,x=map(int,input().split())
    E.append([s-x-0.5,1,x])
    E.append([t-x-0.5,-1,x])

for a in range(Q):
    E.append([int(input()),0,0])
E.sort(key=lambda x:x[0])
 
S=set()
H=[]
for time_,type_,x in E:
    if type_==1:
        S.add(x)
        heapq.heappush(H,x)
    elif type_==-1:
        S.remove(x)
    else:
        while H and H[0] not in S:
            heapq.heappop(H)
        print(H[0] if H else -1)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import re
import math
import fractions
import random
import heapq
import time
import sys
input = sys.stdin.readline
#import numpy as np
mod=int(10**9+7)
inf=int(10**20)
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def comb(n,r):return math.factorial(n)//math.factorial(n-r)//math.factorial(r)
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
 
 
#main
N,Q=map(int,input().split())
E=[]
for a in range(N):
    s,t,x=map(int,input().split())
    E.append([s-x-0.5,1,x])
    E.append([t-x-0.5,-1,x])

for a in range(Q):
    E.append([int(input()),0,0])
E.sort(key=lambda x:x[0])
 
S=set()
H=[]
for time_,type_,x in E:
    if type_==1:
        S.add(x)
        heapq.heappush(H,x)
    elif type_==-1:
        S.remove(x)
    else:
        if len(S)==0:
            print(-1)
        else:
            while H[0] not in S:
                heapq.heappop(H)
            print(H[0])

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import re
import math
import fractions
import random
import heapq
import time
import sys
input = sys.stdin.readline
#import numpy as np
mod=int(10**9+7)
inf=int(10**20)
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def comb(n,r):return math.factorial(n)//math.factorial(n-r)//math.factorial(r)
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
 
 
#main
N,Q=map(int,input().split())
E=[]
for a in range(N):
    s,t,x=map(int,input().split())
    E.append([s-x-0.5,1,x])
    E.append([t-x-0.5,-1,x])

for a in range(Q):
    E.append([int(input()),0,0])
E.sort(key=lambda x:x[0])
 
S=set()
H=[]
for a in E:
    x=a[2]
    type_=a[1]
    if type_==1:
        S.add(x)
        heapq.heappush(H,x)
    elif type_==-1:
        S.remove(x)
    else:
        if len(S)==0:
            print(-1)
        else:
            while H[0] not in S:
                heapq.heappop(H)
            print(H[0])

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import re
import math
import fractions
import random
import heapq
import time
import sys
input = sys.stdin.readline
#import numpy as np
mod=int(10**9+7)
inf=int(10**20)
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def comb(n,r):return math.factorial(n)//math.factorial(n-r)//math.factorial(r)
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
 
 
#main
def solve():
    return
 
#入力
N,Q=map(int,input().split())
 
E=[]
for a in range(N):
    s,t,x=map(int,input().split())
    E.append([s-x-0.5,1,x])
    E.append([t-x-0.5,-1,x])
 
for a in range(Q):
    E.append([int(input()),0,0])
E.sort(key=lambda x:x[0])
 
S=set()
H=[]
for a in E:
    x=a[2]
    type_=a[1]
    if type_==1:
        S.add(x)
        heapq.heappush(H,x)
    elif type_==-1:
        S.remove(x)
    else:
        if len(S)==0:
            print(-1)
        else:
            while H[0] not in S:
                heapq.heappop(H)
            print(H[0])

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import re
import math
import fractions
import random
import heapq
import time
import sys
input = sys.stdin.readline
#import numpy as np
mod=int(10**9+7)
inf=int(10**20)
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n

    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]

    def same(self,x,y):
        return self.find(x)==self.find(y)

    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1

    def unite(self,x,y):
        self.link(self.find(x),self.find(y))

    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def comb(n,r):return math.factorial(n)//math.factorial(n-r)//math.factorial(r)
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num


#main
def solve():
    return

#入力
N,Q=map(int,input().split())

E=[]
for a in range(N):
    s,t,x=map(int,input().split())
    E.append([s-x-0.5,1,x])
    E.append([t-x-0.5,-1,x])

for a in range(Q):
    E.append([int(input()),0,0])
E.sort(key=lambda x:x[0])

S=set()
H=[]
for a in E:
    x=a[2]
    type_=a[1]
    if type_==1:
        S.add(x)
        heapq.heappush(H,x)
    elif type_==-1:
        S.remove(x)
    else:
        if len(S)==0:
            print(-1)
        else:
            while H[0] and H[0] not in S:
                heapq.heappop(H)
            print(H[0])

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import re
import math
import fractions
import random
import heapq
import time
import sys
input = sys.stdin.readline
#import numpy as np
mod=int(10**9+7)
inf=int(10**20)
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n

    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]

    def same(self,x,y):
        return self.find(x)==self.find(y)

    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1

    def unite(self,x,y):
        self.link(self.find(x),self.find(y))

    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def comb(n,r):return math.factorial(n)//math.factorial(n-r)//math.factorial(r)
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num


#main
def solve():
    return

#入力
N,Q=map(int,input().split())

E=[]
for a in range(N):
    s,t,x=map(int,input().split())
    E.append([s-x-0.5,1,x])
    E.append([t-x-0.5,-1,x])

for a in range(Q):
    E.append([int(input()),0,0])
E.sort(key=lambda x:x[0])

S=set()
H=[]
for a in E:
    x=a[2]
    type_=a[1]
    if type_==1:
        S.add(x)
        heapq.heappush(H,x)
    elif type_==-1:
        S.remove(x)
    else:
        if len(S)==0:
            print(-1)
        else:
            while H[0] not in S:
                heapq.heappop(H)
            print(H[0])

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import re
import math
import fractions
import random
import heapq
import time
import sys
input = sys.stdin.readline
#import numpy as np
mod=int(10**9+7)
inf=int(10**20)
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n

    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]

    def same(self,x,y):
        return self.find(x)==self.find(y)

    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1

    def unite(self,x,y):
        self.link(self.find(x),self.find(y))

    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def comb(n,r):return math.factorial(n)//math.factorial(n-r)//math.factorial(r)
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num


#main
def solve():
    return

#入力
N,Q=map(int,input().split())

E=[]
for a in range(N):
    s,t,x=map(int,input().split())
    E.append([s-x-0.5,1,x])
    E.append([t-x-0.5,-1,x])

for a in range(Q):
    E.append([int(input()),0,0])
E.sort(key=lambda x:x[0])

S=set()
H=[]
for a in E:
    x=a[2]
    type_=a[1]
    if type_==1:
        S.add(x)
        heapq.heappush(H,x)
    elif type_==-1:
        S.remove(x)
    else:
        if len(S)==0:
            print(-1)
        else:
            while H[0] not in S:
                heapq.heappop(H)
            print(H[0])

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import re
import math
import fractions
import random
import heapq
import time
#import numpy as np
mod=int(10**9+7)
inf=int(10**20)
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n

    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]

    def same(self,x,y):
        return self.find(x)==self.find(y)

    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1

    def unite(self,x,y):
        self.link(self.find(x),self.find(y))

    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def comb(n,r):return math.factorial(n)//math.factorial(n-r)//math.factorial(r)
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num


#main
def solve():
    return

#入力
N,Q=map(int,input().split())
S=[0]*N
T=[0]*N
X=[0]*N

D=[]
for a in range(N):
    S[a],T[a],X[a]=map(int,input().split())


E=[]
for a in range(N):
    E.append([S[a]-X[a]-0.5,1,X[a]])
    E.append([T[a]-X[a]-0.5,-1,X[a]])

for a in range(Q):
    E.append([int(input()),0,0])
E.sort(key=lambda x:x[0])


S=set()
H=[]
for a in E:
    x=a[2]
    val=a[0]
    type_=a[1]
    if type_==1:
        S.add(x)
        heapq.heappush(H,x)
    elif type_==-1:
        S.remove(x)
    else:
        if len(S)==0:
            print(-1)
        else:
            while H[0] not in S:
                heapq.heappop(H)
            print(H[0])