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++14 (GCC 5.4.1) (judge verdict: Accepted)

#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////
template <typename T>
class segment_base {
	int N;//要素数
	vector< T > dat;
	vector<T> lazy;//遅延

	T VAL_E;//初期値
public:
	segment_base() {};
	segment_base(int n, T val_E){
		N = 2;
		while (n > N) {
			N = N * 2;
		}
		VAL_E = val_E;

		dat.resize(2 * N);
		dat.assign(2 * N, val_E);//初期化
		lazy = vector<T>(2 * N, val_E);
	}
	
	T SELECT(T LDat, T RDat) {//扱う演算子
		T ans;
		ans = min(LDat, RDat);//
		return ans;
	}

	void eval(int k) {
		if (lazy[k] == LINF) return;
		if (k < N) {//葉でない
			lazy[k * 2 + 0] = lazy[k];
			lazy[k * 2 + 1] = lazy[k];
		}
		dat[k] = lazy[k];
		lazy[k] = LINF;
	}
	/*
	[a,b),[0,N)
	*/
	T update_sub(int a, int b, int k, int L, int R,T val) {
		eval(k);
		if (R <= a || b <= L) {
			return VAL_E;
		}
		else if (a <= L && R <= b) {
			lazy[k] = val;
			eval(k);//dat[k]も更新している。
			return dat[k];
		}
		else {
			T vL = update_sub(a, b, k * 2 + 0, L, (L + R) / 2, val);
			T vR = update_sub(a, b, k * 2 + 1, (L + R) / 2, R, val);
			dat[k] = SELECT(vL,vR);
			return dat[k];
		}
		return VAL_E;//来ない
	}
	
	T update(int a, int b,T val) {
		return update_sub(a, b, 1, 0, N, val);
	}

	//区間[L,R)のSELECT
	T query_sub(int a, int b, int k, int L, int R) {
		eval(k);//遅延評価
		if (R <= a || b <= L) {
			return VAL_E;
		}
		else if (a <= L && R <= b) {
			return dat[k];
		}
		else {
			T vL = query_sub(a, b, k * 2 + 0, L, (L + R) / 2);
			T vR = query_sub(a, b, k * 2 + 1, (L + R) / 2, R);
			return SELECT(vL, vR);
		}
	}
	//区間[L,R)
	T query(int L, int R) {
		T ans = query_sub(L, R, 1, 0, N);
		return ans;
	}
};

void solve() {
	int N, Q;
	cin >> N >> Q;
	vector<vector<int>>que(N,vector<int>(3));
	for (int i = 0; i < N; ++i) {
		cin >> que[i][1] >> que[i][2] >> que[i][0];
	}
	sort(que.begin(), que.end());
	reverse(que.begin(), que.end());

	vector<int> D(Q);
	for (int i = 0; i < Q; ++i) {
		cin >> D[i];
	}
	
	/*
	区間の値をセットする。
	最小値か最大値化を得られればOK
	[S,T)の区間をS-1にする。
	S,Tを番号化する。
	その区間をSで置き換えたいけど
	小さい値は残しておきたい。
	そのあと各場所で
	じゃあ、Xを後ろからやって
	区間にSを入れていく。？
	X-1まであるけるから
	ぶつかった区間を入れていく。
	区間更新
	一か所の値を得られれば良い。
	*/
    
	segment_base<LL> sg(Q, LINF);//最小値を探すからこれ
	/*
	関数名で使い分けたほうがいいか？
	*/

	//工事場所のXでソート、反転したので、
	//直更新してOK
	for (int i = 0; i <N; ++i) {
		LL S = que[i][1];
		LL T = que[i][2];
        LL X = que[i][0];

		int Sind, Tind;
		Sind = lower_bound(D.begin(), D.end(), S-X) - D.begin();
		Tind = lower_bound(D.begin(), D.end(), T-X) - D.begin();
		//[Sind,Tind)の区間をque[i][0]に更新する。
		sg.update(Sind, Tind,X);
	}
    for (int i = 0; i < Q; ++i) {
		LL res = sg.query(i, i + 1);
        if (res == LINF) {
            res = -1;
        }
        cout << res << endl;
    }
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}