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)

#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "{ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "}";

    return os;
}

ll pow_mod(ll a, ll p) {
    ll res = 1;
    while(p) {
        if (p & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        p >>= 1;
    }

    return res;
}


ll mod_inv(ll a, ll m) {
    ll b = m, u = 0, v = 1;
    while(a) {
        ll t = b / a;
        swap(b -= t * a, a);
        swap(u -= t * v, v);
    }

    return (u % m + m) % m;
}

ll gcd(ll a, ll b) {
    if(b == 0) return a;
    return gcd(b, a%b);
}

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#ifdef LOCAL
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

const int NMAX = int(1e6);

map<ll, int> zip;
ll unzip[NMAX];

int compress(vector<ll>& v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    REP (i, v.size()) {
        zip[v[i]] = i;
        unzip[i] = v[i];
    }
    return v.size();
}


int get_n(int n) {
    int ret = 1; while(ret < n) ret <<= 1;

    return ret;
}

struct SegTree {
    int N;
    vector<ll> dat;
    vector<ll> lazy;

    explicit SegTree(int n): N(get_n(n)), dat(2*N-1, INF), lazy(2*N-1, INF) {}

    void eval(int k, int l, int r) {
        if (lazy[k] < INF) {
            dat[k] = min(dat[k], lazy[k]);

            if (r - l > 1) {
                lazy[2*k+1] = min(lazy[2*k+1], lazy[k]);
                lazy[2*k+2] = min(lazy[2*k+2], lazy[k]);
            }

            lazy[k] = INF;
        }
    }

    void update(int a, int b, ll v, int k=0, int l=0, int r=-1) {
        if(r < 0) r = N;

        if (b <= l || r <= a) return;
      
        eval(k, l, r);

        if (a <= l && r <= b) {
            lazy[k] = min(lazy[k], v);
            return;
        }

        int mid = (l + r) / 2;
        update(a, b, v, 2 * k + 1, l, mid);
        update(a, b, v, 2 * k + 2, mid, r);
    }

    ll query(int a, int b=-1, int k=0, int l=0, int r=-1) {
        if (r < 0) r = N;
        if (b < 0) b = a + 1;

        if (b <= l || r <= a) return INF;
      
        eval(k, l, r);

        if (a <= l && r <= b) return dat[k];

        int mid = (l + r) / 2;
        ll c0 = query(a, b, 2 * k + 1, l, mid);
        ll c1 = query(a, b, 2 * k + 2, mid, r);

        return min(c0, c1);
    }

    void print() {
        cout << "dat: " << endl;
        REP(i, dat.size()) {
            if (i > 0) cout << " ";

            if (dat[i] > NMAX) cout << "INF";
            else cout << dat[i];
        }

        cout << endl;

        cout << "lazy: " << endl;
        REP(i, lazy.size()) {
            if (i > 0) cout << " ";

            if (lazy[i] > NMAX) cout << "INF";
            else cout << lazy[i];
        }

        cout << endl;
    }
};



int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N, Q;
    cin >> N >> Q;

    vector<ll> S(N), T(N), X(N);
    REP(i, N) {
        ll s, t, x;
        cin >> s >> t >> x;
        S[i] = s - x;
        T[i] = t - x;
        X[i] = x;
    }

    vector<ll> D(Q);
    REP(i, Q) {
        cin >> D[i];
    }

    vector<ll> tmp(3 * N + Q);
    copy(S.begin(), S.end(), tmp.begin());
    copy(T.begin(), T.end(), tmp.begin() + N);
    copy(X.begin(), X.end(), tmp.begin() + 2*N);
    copy(D.begin(), D.end(), tmp.begin() + 3*N);

    compress(tmp);

    SegTree st(zip.size());

    REP(i, N) {
        st.update(zip[S[i]], zip[T[i]], zip[X[i]]);
    }


    REP(i, Q) {
        ll ans = st.query(zip[D[i]]);
        if (ans == INF) cout << -1 << endl;
        else cout << unzip[ans] << endl;
    }

}