Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

void solve() {
  ll n;
  cin >> n;
  ll ans = 0;
  vector<ll> k(n), l(n), r(n);
  vector<vector<ll>> L(n + 1), R(n + 1);
  REP(i, n) {
    cin >> k[i] >> l[i] >> r[i];
    ll mini = min(l[i], r[i]);
    ans += mini;
    l[i] -= mini;
    r[i] -= mini;
    if (l[i] > r[i]) {
      L[k[i]].push_back(i);
    } else if (l[i] < r[i]) {
      R[k[i]].push_back(i);
    }
  }

  priority_queue<P> pq;

  ll now = 1;
  FOR(i, 1, n + 1) {
    for (ll x : L[i]) {
      pq.push({m[x], x});
    }

    while (!pq.empty()) {
      P p = pq.front();
      pq.pop();
      if (p.second >= now) {
        ans += m[p.second];
        now++;
      }
    }
  }

  now = n;
  IFOR(i, 1, n + 1) {
    for (ll x : R[i]) {
      pq.push({m[x], x});
    }

    while (!pq.empty()) {
      P p = pq.front();
      pq.pop();
      if (p.second < now) {
        ans += m[p.second];
        break;
      }
    }
  }

  cout << ans << endl;
}

int main() {
  int t;
  scanf("%d", &t);
  while (t--) solve();
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:38:16: error: 'm' was not declared in this scope
   38 |       pq.push({m[x], x});
      |                ^
a.cc:38:14: error: no matching function for call to 'std::priority_queue<std::pair<long long int, long long int> >::push(<brace-enclosed initializer list>)'
   38 |       pq.push({m[x], x});
      |       ~~~~~~~^~~~~~~~~~~
In file included from /usr/include/c++/14/queue:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:157,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_queue.h:736:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = std::pair<long long int, long long int>; _Sequence = std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >; _Compare = std::less<std::pair<long long int, long long int> >; value_type = std::pair<long long int, long long int>]'
  736 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:736:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::priority_queue<std::pair<long long int, long long int> >::value_type&' {aka 'const std::pair<long long int, long long int>&'}
  736 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_queue.h:744:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(value_type&&) [with _Tp = std::pair<long long int, long long int>; _Sequence = std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >; _Compare = std::less<std::pair<long long int, long long int> >; value_type = std::pair<long long int, long long int>]'
  744 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:744:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::priority_queue<std::pair<long long int, long long int> >::value_type&&' {aka 'std::pair<long long int, long long int>&&'}
  744 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
a.cc:42:16: error: 'class std::priority_queue<std::pair<long long int, long long int> >' has no member named 'front'
   42 |       P p = pq.front();
      |                ^~~~~
a.cc:45:16: error: 'm' was not declared in this scope
   45 |         ans += m[p.second];
      |                ^
a.cc:54:16: error: 'm' was not declared in this scope
   54 |       pq.push({m[x], x});
      |                ^
a.cc:54:14: error: no matching function for call to 'std::priority_queue<std::pair<long long int, long long int> >::push(<brace-enclosed initializer list>)'
   54 |       pq.push({m[x], x});
      |       ~~~~~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:736:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = std::pair<long long int, long long int>; _Sequence = std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >; _Compare = std::less<std::pair<long long int, long long int> >; value_type = std::pair<long long int, long long int>]'
  736 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:736:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::priority_queue<std::pair<long long int, long long int> >::value_type&' {aka 'const std::pair<long long int, long long int>&'}
  736 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_queue.h:744:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(value_type&&) [with _Tp = std::pair<long long int, long long int>; _Sequence = std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >; _Compare = std::less<std::pair<long long int, long long int> >; value_type = std::pair<long long int, long long int>]'
  744 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:744:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::priority_queue<std::pair<long long int, long long int> >::value_type&&' {aka 'std::pair<long long int, long long int>&&'}
  744 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
a.cc:58:16: error: 'class std::priority_queue<std::pair<long long int, long long int> >' has no member named 'front'
   58 |       P p = pq.front();
      |                ^~~~~
a.cc:61:16: error: 'm' was not declared in this scope
   61 |         ans += m[p.second];
      |                ^