Language: C++

#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
inline int read(){
	int x=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x;
}
vector<pii >a,b;
ll ans;
int t,n,k,l,r;
multiset<int>s;
inline void f(vector<pii >&v){
	sort(v.begin(),v.end());
	s.clear();
	for(int i=0;i<s.size();i++){
		int x=v[i];
		s.insert(x.sec);
		ans+=x.sec;
		while(s.size()>x.first){
			ans-=*s.begin();
			s.erase(s.begin());
		}
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>t;
	while(t--){
		cin>>n;
		ans=0;
		a.clear(),b.clear();
		for(int i=1;i<=n;i++){
			cin>>k>>l>>r;
			if(l>r)a.pb(k,l-r);
			if(l<r)b.pb(n-k,r-l);
			ans+=min(l,r);
		}
		f(a),f(b);
		cout<<ans<<'\n';
	}
	return 0;
}

Compiler output:
a.cc: In function 'void f(std::vector<std::pair<int, int> >&)':
a.cc:38:26: error: cannot convert '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} to 'int' in initialization
   38 |                 int x=v[i];
      |                          ^
a.cc:5:13: error: request for member 'second' in 'x', which is of non-class type 'int'
    5 | #define sec second
      |             ^~~~~~
a.cc:39:28: note: in expansion of macro 'sec'
   39 |                 s.insert(x.sec);
      |                            ^~~
a.cc:5:13: error: request for member 'second' in 'x', which is of non-class type 'int'
    5 | #define sec second
      |             ^~~~~~
a.cc:40:24: note: in expansion of macro 'sec'
   40 |                 ans+=x.sec;
      |                        ^~~
a.cc:41:34: error: request for member 'first' in 'x', which is of non-class type 'int'
   41 |                 while(s.size()>x.first){
      |                                  ^~~~~
a.cc: In function 'int main()':
a.cc:59:36: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(int&, int)'
   59 |                         if(l>r)a.pb(k,l-r);
      |                                ~~~~^~~~~~~
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:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; value_type = std::pair<int, int>]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; value_type = std::pair<int, int>]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note:   candidate expects 1 argument, 2 provided
a.cc:60:36: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(int, int)'
   60 |                         if(l<r)b.pb(n-k,r-l);
      |                                ~~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; value_type = std::pair<int, int>]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; value_type = std::pair<int, int>]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note:   candidate expects 1 argument, 2 provided