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: Runtime Error)

#include <algorithm>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define moder 1000000007
#define double long double
#define INF LLONG_MAX/10000
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, q, s[200010], t[200010], r1[200010], r2[200010], x[200010], d[200010];
int m, node[2000010], lazy[2000010];
bool lazyflag[2000010];
void init(int n_) {
	m = 1;
	while (m < n_)m *= 2;
	rep(i, 2 * m)node[i] = INF;
}

void eval(int k, int l, int r) {
	if (lazyflag[k]) {
		node[k] = min(node[k], lazy[k]);
		if (r - l > 1) {
			lazy[k * 2 + 1] = lazy[k * 2 + 2] = lazy[k];
			lazyflag[k * 2 + 1] = lazyflag[k * 2 + 2] = true;
		}
		lazyflag[k] = false;
	}
}

void update(int a, int b, int x, int k = 0, int l = 0, int r = -1) {
	if (r < 0)r = m;
	eval(k, l, r);
	if (b <= l || r <= a)return;
	if (a <= l && r <= b) {
		lazy[k] = x;
		lazyflag[k] = true;
		eval(k, l, r);
	}
	else {
		update(a, b, x, 2 * k + 1, l, (l + r) / 2);
		update(a, b, x, 2 * k + 2, (l + r) / 2, r);
		node[k] = min(node[2 * k + 1], node[2 * k + 2]);
	}
}

int query(int a, int b, int k = 0, int l = 0, int r = -1) {
	if (r < 0)r = m;
	eval(k, l, r);
	if (b <= l || r <= a)return INF;
	if (a <= l && r <= b) {
		return node[k];
	}
	int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
	int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
	return min(vl, vr);
}
map<int, int> zaatu;
signed main() {
	cin >> n >> q;
	zaatu[0] = 0;
	rep(i, n) {
		cin >> s[i] >> t[i] >> x[i];
		r1[i] = s[i] - x[i];
		r2[i] = t[i] - x[i];
		r1[i] = max((ll)0, r1[i]);
		zaatu[r1[i]] = zaatu[r2[i]] = 0;
	}
	rep(i, q) {
		cin >> d[i];
		zaatu[d[i]] = 0;
	}
	int cnt = 0;
	for (auto i = zaatu.begin(); i != zaatu.end(); i++) {
		(*i).second = cnt;
		cnt++;
	}
	rep(i, n) {
		r1[i] = zaatu[r1[i]];
		r2[i] = zaatu[r2[i]];
	}
	rep(i, q)d[i] = zaatu[d[i]];
	init(1000000);
	rep(i, n) {
		if (r2[i] < zaatu[0])continue;
		update(r1[i], r2[i], x[i]);
	}
	int ans = 0;
	rep(i, q) {
		int memo = query(d[i], d[i] + 1);
		if (memo == INF)cout << -1 << endl;
		else cout << memo << endl;
	}
	return 0;
}