Language: C++

#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, S, E) for(int(X) = (S); (X) < (E); ++(X))
#define rrep(X, S, E) for(int(X) = (E)-1; (X) >= (S); --(X))
#define itrep(X, Y) for(auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef priority_queue<ll, vl> decendingQueue;              //降順
typedef priority_queue<ll, vl, greater<ll>> ascendingQueue; //昇順
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll INF = 9 * 1e18;
const ll MOD = 1e9 + 7;

void solve(long long N, long long Q, std::vector<long long> S,
           std::vector<long long> T, std::vector<long long> X,
           std::vector<long long> D) {
    vector<pll, greater<pll>> construction;
    rep(i, 0, N) { construction.push_back(mp(X[i], i)); }
    sort(all(construction));

    vl ans(Q, -1);
    rep(i, 0, N) {
        ll x = construction[i].fi;
        ll index = construction[i].sc;

        ll from = lower_bound(all(D), S[index] - x) - D.begin();
        ll to = lower_bound(all(D), T[index] - x) - D.begin();
        rep(j, from, to) {
            ans[j] = x;
            D.erase(D.begin() + j);
        }
    }
    rep(j, 0, Q) { print(ans[j]); }
}

int main() {
    long long N;
    scanf("%lld", &N);
    long long Q;
    scanf("%lld", &Q);
    std::vector<long long> S(N);
    std::vector<long long> T(N);
    std::vector<long long> X(N);
    for(int i = 0; i < N; i++) {
        scanf("%lld", &S[i]);
        scanf("%lld", &T[i]);
        scanf("%lld", &X[i]);
    }
    std::vector<long long> D(Q);
    for(int i = 0; i < Q; i++) {
        scanf("%lld", &D[i]);
    }
    solve(N, Q, std::move(S), std::move(T), std::move(X), std::move(D));
    return 0;
}


Compiler output:
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'struct std::_Vector_base<std::pair<long long int, long long int>, std::greater<std::pair<long long int, long long int> > >':
/usr/include/c++/14/bits/stl_vector.h:428:11:   required from 'class std::vector<std::pair<long long int, long long int>, std::greater<std::pair<long long int, long long int> > >'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
a.cc:45:31:   required from here
   45 |     vector<pll, greater<pll>> construction;
      |                               ^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:87:28: error: no type named 'value_type' in 'struct std::greater<std::pair<long long int, long long int> >'
   87 |         rebind<_Tp>::other _Tp_alloc_type;
      |                            ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:89:9: error: no type named 'value_type' in 'struct std::greater<std::pair<long long int, long long int> >'
   89 |         pointer;
      |         ^~~~~~~
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'class std::vector<std::pair<long long int, long long int>, std::greater<std::pair<long long int, long long int> > >':
a.cc:45:31:   required from here
   45 |     vector<pll, greater<pll>> construction;
      |                               ^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:518:20: error: '_M_allocate' has not been declared in 'std::vector<std::pair<long long int, long long int>, std::greater<std::pair<long long int, long long int> > >::_Base'
  518 |       using _Base::_M_allocate;
      |                    ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:519:20: error: '_M_deallocate' has not been declared in 'std::vector<std::pair<long long int, long long int>, std::greater<std::pair<long long int, long long int> > >::_Base'
  519 |       using _Base::_M_deallocate;
      |                    ^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:521:20: error: '_M_get_Tp_allocator' has not been declared in 'std::vector<std::pair<long long int, long long int>, std::greater<std::pair<long long int, long long int> > >::_Base'
  521 |       using _Base::_M_get_Tp_allocator;
      |                    ^~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:59,
                 from /usr/include/c++/14/algorithm:60,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'std::_Vector_base<_Tp, _Alloc>::_Vector_impl::_Vector_impl() [with _Tp = std::pair<long long int, long long int>; _Alloc = std::greater<std::pair<long long int, long long int> >]':
a.cc:45:31:   required from here
   45 |     vector<pll, greater<pll>> construction;
      |                               ^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:136:24: error: no type named 'value_type' in 'struct std::greater<std::pair<long long int, long long int> >'
  136 |         _Vector_impl() _GLIBCXX_NOEXCEPT_IF(
      |                        ^~~~~~~~~~~~~~~~~~~~
a.cc: In function 'void solve(long long int, long long int, std::vector<long long int>, std::vector<long long int>, std::vector<long long int>, std::vector<long long int>)':
a.cc:23:20: error: 'class std::vector<std::pair<long long int, long long int>, std::greater<std::pair<long long int, long long int> > >' has no member named 'begin'
   23 | #define all(X) (X).begin(), (X).end()
      |                    ^~~~~
a.cc:47:10: note: in expansion of macro 'all'
   47 |     sort(all(construction));
      |          ^~~
a.cc:23:33: error: 'class std::vector<std::pair<long long int, long long int>, std::greater<std::pair<long long int, long long int> > >' has no member named 'end'
   23 | #define all(X) (X).begin(), (X).end()
      |                                 ^~~
a.cc:47:10: note: in expansion of macro 'all'
   47 |     sort(all(construction));
      |          ^~~
a.cc:51:28: error: no match for 'operator[]' (operand types are 'std::vector<std::pair<long long int, long long int>, std::greater<std::pair<long long int, long long int> > >' and 'int')
   51 |         ll x = construction[i].fi;
      |                            ^
a.cc:52:32: error: no match for 'operator[]' (operand types are 'std::vector<std::pair<long long int, long long int>, std::greater<std::pair<long long int, long long int> > >' and 'int')
   52 |         ll index = construction[i].sc;
      |                                ^
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'std::_Vector_base<_Tp, _Alloc>::_Vector_impl::_Vector_impl() [with _Tp = std::pair<long long int, long long int>; _Alloc = std::greater<std::pair<long long int, long long int> >]':
/usr/include/c++/14/bits/stl_vector.h:314:7:   required from here
  314 |       _Vector_base() = default;
      |       ^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:141:26: error: no type named 'value_type' in 'struct std::greater<std::pair<long long int, long long int> >'
  141 |         : _Tp_alloc_type()
      |                          ^