Language: C++

#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

long long calc(vector<pair<int, long long>> p){
  int n = p.size();
  REP(i, n) p[i].first = min(p[i].first, n);
  vector<vector<long long>> table(n + 1);
  REP(i, n) table[p[i].first].push_back(p[i].second);
  long long res = 0;
  priority_queue<long long> q;
  for(int d = n; d = 1; d--){
    for(long long v: table[d]) q.push(v);
    if(q.empty()) continue;
    long long v = q.top();
    q.pop();
    res += v;
  }
  return res;
}
void solve(int n, vector<int> k, vector<long long> l, vector<long long> r){
  vector<pair<int, long long>> pl, pr;
  long long ans = 0;
  REP(i, n){
    if(l[i] >= r[i]){
      ans += r[i];
      pl.push_back(make_pair(k[i], l[i] - r[i]));
    }else{
      ans += l[i];
      pr.push_back(make_pair(n - k[i], r[i] - l[i]));
    }
  }
  ans += calc(pl);
  ans += calc(pr);
  cout << ans << endl;
  return;
}
      
int main(){
  using namespace std;
  int t;
  cin>>t;
  REP(_, t){
    int n;
    cin>>n;
    vector<int> k[n];
    vector<long long> l[n], r[n];
    REP(i, n) cin>>k[i]>>l[i]>>r[i];
    solve(n, k, l, r);
  }
  return 0;
}


Compiler output:
a.cc:69:16: error: 'vector' was not declared in this scope
   69 | long long calc(vector<pair<int, long long>> p){
      |                ^~~~~~
a.cc:69:16: note: suggested alternatives:
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:1:
/usr/include/c++/14/bits/stl_vector.h:428:11: note:   'std::vector'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/14/vector:93:13: note:   'std::pmr::vector'
   93 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
a.cc:69:23: error: 'pair' was not declared in this scope; did you mean 'std::pair'?
   69 | long long calc(vector<pair<int, long long>> p){
      |                       ^~~~
      |                       std::pair
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_pair.h:89:12: note: 'std::pair' declared here
   89 |     struct pair;
      |            ^~~~
a.cc:69:28: error: expected primary-expression before 'int'
   69 | long long calc(vector<pair<int, long long>> p){
      |                            ^~~
a.cc:69:33: error: expected primary-expression before 'long'
   69 | long long calc(vector<pair<int, long long>> p){
      |                                 ^~~~
a.cc:69:46: error: expression list treated as compound expression in initializer [-fpermissive]
   69 | long long calc(vector<pair<int, long long>> p){
      |                                              ^
a.cc:85:19: error: 'vector' has not been declared
   85 | void solve(int n, vector<int> k, vector<long long> l, vector<long long> r){
      |                   ^~~~~~
a.cc:85:25: error: expected ',' or '...' before '<' token
   85 | void solve(int n, vector<int> k, vector<long long> l, vector<long long> r){
      |                         ^
a.cc: In function 'void solve(int, int)':
a.cc:86:3: error: 'vector' was not declared in this scope
   86 |   vector<pair<int, long long>> pl, pr;
      |   ^~~~~~
a.cc:86:3: note: suggested alternatives:
/usr/include/c++/14/bits/stl_vector.h:428:11: note:   'std::vector'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/14/vector:93:13: note:   'std::pmr::vector'
   93 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
a.cc:86:10: error: 'pair' was not declared in this scope; did you mean 'std::pair'?
   86 |   vector<pair<int, long long>> pl, pr;
      |          ^~~~
      |          std::pair
/usr/include/c++/14/bits/stl_pair.h:89:12: note: 'std::pair' declared here
   89 |     struct pair;
      |            ^~~~
a.cc:86:15: error: expected primary-expression before 'int'
   86 |   vector<pair<int, long long>> pl, pr;
      |               ^~~
a.cc:89:8: error: 'l' was not declared in this scope
   89 |     if(l[i] >= r[i]){
      |        ^
a.cc:89:16: error: 'r' was not declared in this scope
   89 |     if(l[i] >= r[i]){
      |                ^
a.cc:91:7: error: 'pl' was not declared in this scope; did you mean 'po'?
   91 |       pl.push_back(make_pair(k[i], l[i] - r[i]));
      |       ^~
      |       po
a.cc:91:30: error: 'k' was not declared in this scope
   91 |       pl.push_back(make_pair(k[i], l[i] - r[i]));
      |                              ^
a.cc:91:20: error: 'make_pair' was not declared in this scope; did you mean 'std::make_pair'?
   91 |       pl.push_back(make_pair(k[i], l[i] - r[i]));
      |                    ^~~~~~~~~
      |                    std::make_pair
/usr/include/c++/14/bits/stl_pair.h:1132:5: note: 'std::make_pair' declared here
 1132 |     make_pair(_T1&& __x, _T2&& __y)
      |     ^~~~~~~~~
a.cc:94:7: error: 'pr' was not declared in this scope; did you mean 'po'?
   94 |       pr.push_back(make_pair(n - k[i], r[i] - l[i]));
      |       ^~
      |       po
a.cc:94:34: error: 'k' was not declared in this scope
   94 |       pr.push_back(make_pair(n - k[i], r[i] - l[i]));
      |                                  ^
a.cc:94:20: error: 'make_pair' was not declared in this scope; did you mean 'std::make_pair'?
   94 |       pr.push_back(make_pair(n - k[i], r[i] - l[i]));
      |                    ^~~~~~~~~
      |                    std::make_pair
/usr/include/c++/14/bits/stl_pair.h:1132:5: note: 'std::make_pair' declared here
 1132 |     make_pair(_T1&& __x, _T2&& __y)
      |     ^~~~~~~~~
a.cc:97:15: error: 'pl' was not declared in this scope; did you mean 'po'?
   97 |   ans += calc(pl);
      |               ^~
      |               po
a.cc:97:17: error: 'calc' cannot be used as a function
   97 |   ans += calc(pl);
      |                 ^
a.cc:98:15: error: 'pr' was not declared in this scope; did you mean 'po'?
   98 |   ans += calc(pr);
      |               ^~
      |               po
a.cc:98:17: error: 'calc' cannot be used as a function
   98 |   ans += calc(pr);
      |                 ^
a.cc:99:3: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   99 |   cout << ans << endl;
      |   ^~~~
      |   std::cout
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:146:
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:99:18: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   99 |   cout << ans << endl;
      |                  ^~~~
      |                  std::endl
In file included from /usr/include/c++/14/istream:41,
                 from /usr/include/c++/14/sstream:40,
                 from /usr/include/c++/14/complex:45,
                 from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127:
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~
a.cc: In function 'int main()':
a.cc:112:18: error: no match for 'operator>>' (operand types are 'std::istream' {aka 'std::basic_istream<char>'} and 'std::vector<int>')
  112 |     REP(i, n) cin>>k[i]>>l[i]>>r[i];
      |               ~~~^~~~~~
      |               |       |
      |               |       std::vector<int>
      |               std::istream {aka std::basic_istream<char>}
/usr/include/c++/14/istream:170:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]'
  170 |       operator>>(bool& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:170:24: note:   no known conversion for argument 1 from 'std::vector<int>' to 'bool&'
  170 |       operator>>(bool& __n)
      |                  ~~~~~~^~~
/usr/include/c++/14/istream:174:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char; _Traits = std::char_traits<char>]'
  174 |       operator>>(short& __n);
      |       ^~~~~~~~
/usr/include/c++/14/istream:174:25: note:   no known conversion for argument 1 from 'std::vector<int>' to 'short int&'
  174 |       operator>>(short& __n);
      |                  ~~~~~~~^~~
/usr/include/c++/14/istream:177:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]'
  177 |       operator>>(unsigned short& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:177:34: note:   no known conversion for argument 1 from 'std::vector<int>' to 'short unsigned int&'
  177 |       operator>>(unsigned short& __n)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/istream:181:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char; _Traits = std::char_traits<char>]'
  181 |       operator>>(int& __n);
      |       ^~~~~~~~
/usr/include/c++/14/istream:181:23: note:   no known conversion for argument 1 from 'std::vector<int>' to 'int&'
  181 |       operator>>(int& __n);
      |                  ~~~~~^~~
/usr/include/c++/14/istream:184:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]'
  184 |       operator>>(unsigned int& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:184:32: note:   no known conversion for argument 1 from 'std::vector<int>' to 'unsigned int&'
  184 |       operator>>(unsigned int& __n)
      |                  ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/istream:188:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]'
  188 |       operator>>(long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:188:24: note:   no known conversion for argument 1 from 'std::vector<int>' to 'long int&'
  188 |       operator>>(long& __n)
      |                  ~~~~~~^~~
/usr/include/c++/14/istream:192:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]'
  192 |       operator>>(unsigned long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:192:33: note:   no known conversion for argument 1 from 'std::vector<int>' to 'long unsigned int&'
  192 |       operator>>(unsigned long& __n)
      |                  ~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/istream:199:7: