Language: C++

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int MOD = 1e9+7;
const int MAX = 1e5+7;

struct data{
	int k, l, r;

	data(int a, int b, int c){
		k = a; l = b; r = c;
	}
};

int main(){
	ios::sync_with_stdio(false); cin.tie(0);

	int t; cin >> t;
	while(t--){
		int n; cin >> n;
		vector<data> left, right, mid;
		FOR(i, n){
			int k, l, r; cin >> k >> l >> r;
			if(l > r){
				left.PB(data(k, l, r));
			}else if(l < r){
				right.PB(data(k, l, r));
			}else{
				mid.PB(data(k, l, r));
			}
		}

		sort(all(left), [](data a, data b){
			return a.k < b.k;
		});

		sort(all(right), [](data a, data b){
			return a.k < b.k;
		});

		ll ans = 0;
		int p = 1;
		FOR(i, left.size()){
			if(left[i].k >= p){
				ans += left[i].l;
			}else
				ans += left[i].r;
			p++;
		}

		FOR(i, mid.size()){
			ans+=mid[i].l;
			p++;
		}

		FOR(i, right.size()){
			if(right[i].k >= p){
				ans += right[i].l;
			}else
				ans += right[i].r;
			p++;
		}

		cout << ans << '\n';
		//FOR(i, n) cout << v[i].k << ' ' << v[i].l << ' ' << v[i].r << '\n';
	}

	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:33:28: error: template argument 1 is invalid
   33 |                 vector<data> left, right, mid;
      |                            ^
a.cc:33:28: error: template argument 2 is invalid
a.cc:6:12: error: request for member 'push_back' in 'left', which is of non-class type 'int'
    6 | #define PB push_back
      |            ^~~~~~~~~
a.cc:37:38: note: in expansion of macro 'PB'
   37 |                                 left.PB(data(k, l, r));
      |                                      ^~
a.cc:37:41: error: reference to 'data' is ambiguous
   37 |                                 left.PB(data(k, l, r));
      |                                         ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:19:8: note:                 'struct data'
   19 | struct data{
      |        ^~~~
a.cc:6:12: error: request for member 'push_back' in 'right', which is of non-class type 'int'
    6 | #define PB push_back
      |            ^~~~~~~~~
a.cc:39:39: note: in expansion of macro 'PB'
   39 |                                 right.PB(data(k, l, r));
      |                                       ^~
a.cc:39:42: error: reference to 'data' is ambiguous
   39 |                                 right.PB(data(k, l, r));
      |                                          ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:19:8: note:                 'struct data'
   19 | struct data{
      |        ^~~~
a.cc:6:12: error: request for member 'push_back' in 'mid', which is of non-class type 'int'
    6 | #define PB push_back
      |            ^~~~~~~~~
a.cc:41:37: note: in expansion of macro 'PB'
   41 |                                 mid.PB(data(k, l, r));
      |                                     ^~
a.cc:41:40: error: reference to 'data' is ambiguous
   41 |                                 mid.PB(data(k, l, r));
      |                                        ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:19:8: note:                 'struct data'
   19 | struct data{
      |        ^~~~
a.cc:7:18: error: request for member 'begin' in 'left', which is of non-class type 'int'
    7 | #define all(x) x.begin(), x.end()
      |                  ^~~~~
a.cc:45:22: note: in expansion of macro 'all'
   45 |                 sort(all(left), [](data a, data b){
      |                      ^~~
a.cc:7:29: error: request for member 'end' in 'left', which is of non-class type 'int'
    7 | #define all(x) x.begin(), x.end()
      |                             ^~~
a.cc:45:22: note: in expansion of macro 'all'
   45 |                 sort(all(left), [](data a, data b){
      |                      ^~~
a.cc:45:36: error: reference to 'data' is ambiguous
   45 |                 sort(all(left), [](data a, data b){
      |                                    ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:19:8: note:                 'struct data'
   19 | struct data{
      |        ^~~~
a.cc:45:36: error: 'data' has not been declared
   45 |                 sort(all(left), [](data a, data b){
      |                                    ^~~~
a.cc:45:44: error: reference to 'data' is ambiguous
   45 |                 sort(all(left), [](data a, data b){
      |                                            ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:19:8: note:                 'struct data'
   19 | struct data{
      |        ^~~~
a.cc:45:44: error: 'data' has not been declared
   45 |                 sort(all(left), [](data a, data b){
      |                                            ^~~~
a.cc: In lambda function:
a.cc:46:34: error: request for member 'k' in 'a', which is of non-class type 'int'
   46 |                         return a.k < b.k;
      |                                  ^
a.cc:46:40: error: request for member 'k' in 'b', which is of non-class type 'int'
   46 |                         return a.k < b.k;
      |                                        ^
a.cc: In function 'int main()':
a.cc:7:18: error: request for member 'begin' in 'right', which is of non-class type 'int'
    7 | #define all(x) x.begin(), x.end()
      |                  ^~~~~
a.cc:49:22: note: in expansion of macro 'all'
   49 |                 sort(all(right), [](data a, data b){
      |                      ^~~
a.cc:7:29: error: request for member 'end' in 'right', which is of non-class type 'int'
    7 | #define all(x) x.begin(), x.end()
      |                             ^~~
a.cc:49:22: note: in expansion of macro 'all'
   49 |                 sort(all(right), [](data a, data b){
      |                      ^~~
a.cc:49:37: error: reference to 'data' is ambiguous
   49 |                 sort(all(right), [](data a, data b){
      |                                     ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data())