Problem:
Score : 500 points

Problem Statement

There is an infinitely long street that runs west to east, which we consider as a number line.

There are N roadworks scheduled on this street.
The i-th roadwork blocks the point at coordinate X_i from time S_i - 0.5 to time T_i - 0.5.

Q people are standing at coordinate 0. The i-th person will start the coordinate 0 at time D_i, continue to walk with speed 1 in the positive direction and stop walking when reaching a blocked point.

Find the distance each of the Q people will walk.

Constraints

All values in input are integers.

1 \leq N, Q \leq 2 \times 10^5

0 \leq S_i < T_i \leq 10^9

1 \leq X_i \leq 10^9

0 \leq D_1 < D_2 < ... < D_Q \leq 10^9

If i \neq j and X_i = X_j, the intervals [S_i, T_i) and [S_j, T_j) do not overlap.

Input

Input is given from Standard Input in the following format:

N Q
S_1 T_1 X_1
:
S_N T_N X_N
D_1
:
D_Q

Output

Print Q lines. The i-th line should contain the distance the i-th person will walk or -1 if that person walks forever.

Sample Input 1

4 6
1 3 2
7 13 10
18 20 13
3 4 2
0
1
2
3
5
8

Sample Output 1

2
2
10
-1
13
-1

The first person starts coordinate 0 at time 0 and stops walking at coordinate 2 when reaching a point blocked by the first roadwork at time 2.

The second person starts coordinate 0 at time 1 and reaches coordinate 2 at time 3. The first roadwork has ended, but the fourth roadwork has begun, so this person also stops walking at coordinate 2.

The fourth and sixth persons encounter no roadworks while walking, so they walk forever. The output for these cases is -1.

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using static System.Console;
using static System.Math;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		int[] s=sc.Ia;
		int[][] a=new int[s[0]][];
		int[] b=new int[s[1]];
		for(int i = 0;i<s[0];i++) {
			a[i]=sc.Ia;
			int q=a[i][1]-a[i][2]-1;
			if(q>=0){
				a[i][1]=q;
				q=Max(a[i][0]-a[i][2],0);
				a[i][0]=q;
			}
			else{a[i][2]=-1;}
		}
		for(int i = 0;i<s[1];i++) {b[i]=sc.I;}
		Array.Sort(a,(u,v)=>v[2]-u[2]);
		St2 st=new St2(0,s[1]);
		for(int i = 0;i<s[0]&&a[i][2]!=-1;i++) {
			int lb=-1,ub=s[1]-1,mid=0;
			while(ub-lb>1){
				mid=(ub+lb)/2;
				if(b[mid]>=a[i][0]){ub=mid;}
				else{lb=mid;}
			}
			int p=ub;
			lb=0;ub=s[1];mid=0;
			while(ub-lb>1){
				mid=(ub+lb)/2;
				if(b[mid]>=a[i][1]+1){ub=mid;}
				else{lb=mid;}
			}
			st.Ud3(p,lb,a[i][2]);
		}
		StringBuilder sb=new StringBuilder();
		for(int i = 0;i<s[1];i++) {
			long q=st.Get(i,i);
			sb.Append((q==0?-1:q)+"\n");
		}
		Write(sb);
	}
}
public class St2{
	public long[] dat,dat3;
	private bool[] bo3;
	private int m=1,f,sr=1,cnt=0;
	public St2(int f,int n){
		this.f=f;n+=f^1;
		while(m<n){m*=2;sr+=sr;}
		cnt=m+n-1;
		dat=new long[cnt];
		dat3=new long[cnt+1];
		bo3=new bool[cnt];
	}
	private long Fdg(int a,int b,int k,int l,int r){
		if(k>=cnt){return 0;}
		if(bo3[k]){
			dat[k]=dat3[k];
			if(2*k+1<cnt){dat3[2*k+1]=dat3[k]>>1;bo3[2*k+1]=true;}
			if(2*k+2<cnt){dat3[2*k+2]=dat3[k]>>1;bo3[2*k+2]=true;}
			bo3[k]=false;
		}
		if(r<a||b<l){return 0;}
		if(a<=l&&r<=b){return dat[k];}
		else{return Fdg(a,b,k*2+1,l,(l+r)>>1)+Fdg(a,b,k*2+2,(l+r+1)>>1,r);}
	}
	public long Get(int a,int b){return Fdg(a,b,0,f,m-(f^1));}
	public void Ud3(int a,int b,long d){Hn3(a,b,0,f,m-(f^1),d*sr);}
	private long Hn3(int a,int b,int k,int l,int r,long d){
		if(k>=cnt){return 0;}
		if(a<=l&&r<=b){dat3[k]=d;bo3[k]=true;return d;}
		if(bo3[k]){
			dat[k]=dat3[k];
			if(2*k+1<cnt){dat3[2*k+1]=dat3[k]>>1;bo3[2*k+1]=true;}
			if(2*k+2<cnt){dat3[2*k+2]=dat3[k]>>1;bo3[2*k+2]=true;}
			bo3[k]=false;
		}
		if(r>=a&&b>=l){
			dat[k]=Hn3(a,b,k*2+1,l,(l+r)>>1,d>>1)+Hn3(a,b,k*2+2,(l+r+1)>>1,r,d>>1);
			return dat[k];
		}
		return dat[k];
	}
}

public class Sc{
	private string[] a;
	private int n=-1,m=0;
	public int I{get{if(n==-1||n==a.Length-1){n=-1;a=ReadLine().Split();}n++;return int.Parse(a[n]);}}
	public long L{get{if(n==-1||n==a.Length-1){n=-1;a=ReadLine().Split();}n++;return long.Parse(a[n]);}}
	public double D{get{if(n==-1||n==a.Length-1){n=-1;a=ReadLine().Split();}n++;return double.Parse(a[n]);}}
	public string S{get{if(n==-1||n==a.Length-1){n=-1;a=ReadLine().Split();}n++;return a[n];}}
	public string Sz{get{return ReadLine();}}
	public int[] Ia{get{if(n!=-1&&n!=a.Length-1){m=n;n=-1;return Array.ConvertAll(a.Skip(m+1).ToArray(),int.Parse);}return Array.ConvertAll(ReadLine().Split(),int.Parse);}}
	public int[] Ia2(int b){return Array.ConvertAll((((b&1)!=0?"0 ":"")+ReadLine()+((b&2)!=0?" 0":"")).Split(),int.Parse);}
	public long[] La{get{return Array.ConvertAll(ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+ReadLine()+" 0").Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return ReadLine().Split();}}
	public string[] Sa2{get{return (ReadLine()+" 0").Split();}}
}