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: Wrong Answer)

#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

struct event
{
	ll pos, st, en;
};

//半開区間なことに注意
//L<=P<R
template <typename Monoid>
class SegmentTree {
public:
	//コンストラクタ n:サイズ pr:初期値
	SegmentTree(ll n, Monoid pr) {
		size = pow(2, ceil(log2(n)));
		vec.resize(2 * size - 1, pr);
	}

	//値の更新　pos:位置(0-indexed) v:更新後の値
	void Update(ll L, ll R, ll index, ll begin, ll end, Monoid M) {
		//下方向に更新する
		if (vec[index] == -1) {
			vec[index] = min(vec[index], M);
		}
		else if (M != -1) {
			vec[index] = min(vec[index], M);
		}
		if (index >= size - 1) return;
		Update(L, R, index * 2 + 1, begin, (begin + end) / 2, vec[index]);
		Update(L, R, index * 2 + 2, (begin + end) / 2, end, vec[index]);
		return;
	}

	void Update(ll _N) {
		Update(0, _N, 0, 0, size, -1);
	}

	//クエリの処理 L:区間左端 R:区間右端 index:添字(0)
	//begin:ノード左端(0) end:ノード右端(n)
	void Query(ll L, ll R, ll index, ll begin, ll end, Monoid M) {
		if (end <= L || R <= begin) {
			//区間に重ならない
			return;
		}
		if (L <= begin && end <= R) {
			//完全に含む
			if (vec[index] == -1) {
				vec[index] = M;
			}
			else {
				vec[index] = min(vec[index], M);
			}
			return;
		}
		Query(L, R, index * 2 + 1, begin, (begin + end) / 2, M);
		Query(L, R, index * 2 + 2, (begin + end) / 2, end, M);
		return;
	}

	//L<=P<R
	void Query(ll L, ll R, Monoid M) {
		Query(L, R, 0, 0, size, M);
		return;
	}

	void Output(ll N) {
		rep(i, N) cout << vec[size - 1 + i] << endl;
	}

private:
	vector<Monoid> vec;
	ll size;
};

void solve() {
	ll N, Q;
	cin >> N >> Q;
	SegmentTree<ll> ST(Q, -1);
	vector<event> ev(N);
	rep(i, N) {
		ll st, en, pos;
		cin >> ev[i].st >> ev[i].en >> ev[i].pos;
	}

	vector<ll> human(Q);
	rep(i, Q) cin >> human[i];

	rep(i, N) {
		ll start, end;
		//二部探索で範囲を決定
		//最終的にL=Rはtrueの左端で止まる
		//←false→LR←true→
		ll L = 0, R = human.size();
		//全てtrueのときは普通に0が返る
		//全てfalseのとき，sizeが返る
		while (L != R) {
			ll F = (L + R) / 2;
			bool judge = false;

			//判定式
			if (human[F] >= ev[i].en - ev[i].pos) judge = true;

			if (judge) { R = F; }
			else { L = F + 1; }

		}
		end = R;

		L = 0, R = human.size();
		//全てtrueのときは普通に0が返る
		//全てfalseのとき，sizeが返る
		while (L != R) {
			ll F = (L + R) / 2;
			bool judge = false;

			//判定式
			if (human[F] >= ev[i].st - ev[i].pos) judge = true;

			if (judge) { R = F; }
			else { L = F + 1; }

		}

		start = R;

		ST.Query(start, end, ev[i].pos);
		//cout << start << " : " << end << endl;

	}

	ST.Update(Q);

	ST.Output(Q);

}

int main() {
	solve();
	cout << endl;
	return 0;
}