Language: C++

#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iterator>
#include <sstream>

#define FOR(i,a,b) for (long long i=(a);i<(b);i++)
#define RFOR(i,a,b) for (long long i=(b)-1;i>=(a);i--)
#define REP(i,n) for (long long i=0;i<(n);i++)
#define RREP(i,n) for (long long i=(n)-1;i>=0;i--)

#define inf INT_MAX/3
#define INF INT_MAX/3
#define llinf LLONG_MAX/3
#define LLINF LLONG_MAX/3
#define PB push_back
#define pb push_back
#define MP make_pair
#define mp make_pair
#define ALL(a) (a).begin(),(a).end()
#define all(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define PLL pair<long long,long long>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VLL vector<long long>
#define VULL vector<unsigned long long>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define in scanf
#define out printf
#define LL long long
#define ll long long
#define ULL unsigned long long
#define ull unsigned long long
#define eps 1e-14
#define FST first
#define SCD second

using namespace std;

const LL ANS_MAX = 1000000007;

struct Greater
{
	bool operator()(const LL& a, const LL& b)
	{
		return a > b;
	}
};

static bool greater(const LL& a, const LL& b)
{
	return a > b;
}


// ARC074C
int main()
{
	LL ret = - LLINF;

	LL N;
	cin >> N;

	VLL a(3 * N);
	for (size_t i = 0; i < 3 * N; i++) {
		cin >> a[i];
	}

	VLL sum0, sum1;
	//priority_queue<LL, vector<LL>, Greater> a0;
	//priority_queue<LL> a1;
	//for (size_t i = 0; i < N; i++) {
	//	a0.push(a[i]);
	//}
	//for (size_t i = N; i < 3 * N; i++) {
	//	a1.push(a[i]);
	//}

	//LL t = a0.top();
	//LL s = a1.top();

	//make_heap(a0.begin(), a0.end(), greater);
	//pop_heap(a0.begin(), a0.end(), greater);
	//push_heap(a0.begin(), a0.end(), greater);

	for (size_t j = 0; j < N; j++) {
		VLL a0(N + j);
		for (size_t i = 0; i <  N + j; i++) {
			a0[i] = a[i];
		}
		sort(a0.begin(), a0.end(), greater);

		VLL a1(N + N - j);
		for (size_t i = 0; i < N + N - j; i++) {
			a1[i] = a[N + j + i];
		}
		sort(a1.begin(), a1.end());

		LL sum0 = 0;
		for (size_t i = 0; i < N; i++) {
			sum0 += a0[i];
		}

		LL sum1 = 0;
		for (size_t i = 0; i < N; i++) {
			sum1 += a1[i];
		}
		ret = MAX(ret, sum0 - sum1);
	}

	cout << ret << endl;

#if _DEBUG
	cin >> ret;
#endif

	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:25:15: error: 'LLONG_MAX' was not declared in this scope
   25 | #define LLINF LLONG_MAX/3
      |               ^~~~~~~~~
a.cc:79:20: note: in expansion of macro 'LLINF'
   79 |         LL ret = - LLINF;
      |                    ^~~~~
a.cc:15:1: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   14 | #include <iterator>
  +++ |+#include <climits>
   15 | #include <sstream>
a.cc:111:44: error: reference to 'greater' is ambiguous
  111 |                 sort(a0.begin(), a0.end(), greater);
      |                                            ^~~~~~~
In file included from /usr/include/c++/14/bits/refwrap.h:39,
                 from /usr/include/c++/14/vector:68,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_function.h:353:12: note: candidates are: 'template<class _Tp> struct std::greater'
  353 |     struct greater;
      |            ^~~~~~~
a.cc:70:13: note:                 'bool greater(const long long int&, const long long int&)'
   70 | static bool greater(const LL& a, const LL& b)
      |             ^~~~~~~