Language: C++

#include <bits/stdc++.h>
#define sz(a) int((a).size()) 
#define all(c) (c).begin(),(c).end() 
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++) 
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define mp make_pair
#define pb push_back 
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)
#define sd(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sl(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)
#define sortv(a) sort(a.begin(),a.end())
#define test()  int t; cin>>t; while(t--)
#define fi first
#define se second
#define el "\n"
#define ll long long
#define ull unsigned ll
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
 
#define TRACE

#ifndef ONLINE_JUDGE
//FILE *fin = freopen("input.txt","r",stdin);
//FILE *fout = freopen("output.txt","w",stdout);
#endif 
 
#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
 
#else
 
#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)
 
#endif
 
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector< PII > VPII;
 
#define MAXN 100005
ll a[MAXN],lval[MAXN],rval[MAXN];
priority_queue<ll,vector<ll> ,greater<ll> > left;
priority_queue<ll,vector<ll> > right;

int main()
{
	int n;
	cin>>n;
	n = 3*n;
	rep(i,n)
		cin>>a[i+1];
	ll sum = 0;
	for(int i = 1;i<=n;i++)
	{
		if(i<=n/3)
		{
			sum+=a[i];
			left.push(a[i]);
		}
		else
		{
			ll top = left.top();
			if(top<a[i])
			{
				left.pop();
				left.push(a[i]);
				sum+=(a[i]-top);
			}
		}
		lval[i] = sum;
	}
	sum = 0;
	for(int i = n;i>=1;i--)
	{
		if(i>(2*n)/3)
		{
			sum+=a[i];
			right.push(a[i]);
		}
		else
		{
			ll top = right.top();
			if(top>a[i])
			{
				right.pop();
				right.push(a[i]);
				sum+=(a[i]-top);
			}
		}
		rval[i] = sum;
	}
	ll ans = LONG_LONG_MIN;
	/*rep(i,n+1)
		cout<<lval[i]<<" ";
	cout<<endl;
	rep(i,n+1)
		cout<<rval[i]<<" ";
	cout<<endl;
	*/
	for(int i = n/3;i<(2*n)/3;i++)
		ans = max(ans,lval[i]-rval[i+1]);
	cout<<ans<<endl;
	return 0;
} 

Compiler output:
a.cc: In function 'int main()':
a.cc:73:25: error: reference to 'left' is ambiguous
   73 |                         left.push(a[i]);
      |                         ^~~~
In file included from /usr/include/c++/14/streambuf:43,
                 from /usr/include/c++/14/bits/streambuf_iterator.h:35,
                 from /usr/include/c++/14/iterator:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:54,
                 from a.cc:1:
/usr/include/c++/14/bits/ios_base.h:1062:3: note: candidates are: 'std::ios_base& std::left(ios_base&)'
 1062 |   left(ios_base& __base)
      |   ^~~~
a.cc:57:45: note:                 'std::priority_queue<long long int, std::vector<long long int>, std::greater<long long int> > left'
   57 | priority_queue<ll,vector<ll> ,greater<ll> > left;
      |                                             ^~~~
a.cc:77:34: error: reference to 'left' is ambiguous
   77 |                         ll top = left.top();
      |                                  ^~~~
/usr/include/c++/14/bits/ios_base.h:1062:3: note: candidates are: 'std::ios_base& std::left(ios_base&)'
 1062 |   left(ios_base& __base)
      |   ^~~~
a.cc:57:45: note:                 'std::priority_queue<long long int, std::vector<long long int>, std::greater<long long int> > left'
   57 | priority_queue<ll,vector<ll> ,greater<ll> > left;
      |                                             ^~~~
a.cc:80:33: error: reference to 'left' is ambiguous
   80 |                                 left.pop();
      |                                 ^~~~
/usr/include/c++/14/bits/ios_base.h:1062:3: note: candidates are: 'std::ios_base& std::left(ios_base&)'
 1062 |   left(ios_base& __base)
      |   ^~~~
a.cc:57:45: note:                 'std::priority_queue<long long int, std::vector<long long int>, std::greater<long long int> > left'
   57 | priority_queue<ll,vector<ll> ,greater<ll> > left;
      |                                             ^~~~
a.cc:81:33: error: reference to 'left' is ambiguous
   81 |                                 left.push(a[i]);
      |                                 ^~~~
/usr/include/c++/14/bits/ios_base.h:1062:3: note: candidates are: 'std::ios_base& std::left(ios_base&)'
 1062 |   left(ios_base& __base)
      |   ^~~~
a.cc:57:45: note:                 'std::priority_queue<long long int, std::vector<long long int>, std::greater<long long int> > left'
   57 | priority_queue<ll,vector<ll> ,greater<ll> > left;
      |                                             ^~~~
a.cc:93:25: error: reference to 'right' is ambiguous
   93 |                         right.push(a[i]);
      |                         ^~~~~
/usr/include/c++/14/bits/ios_base.h:1070:3: note: candidates are: 'std::ios_base& std::right(ios_base&)'
 1070 |   right(ios_base& __base)
      |   ^~~~~
a.cc:58:32: note:                 'std::priority_queue<long long int, std::vector<long long int> > right'
   58 | priority_queue<ll,vector<ll> > right;
      |                                ^~~~~
a.cc:97:34: error: reference to 'right' is ambiguous
   97 |                         ll top = right.top();
      |                                  ^~~~~
/usr/include/c++/14/bits/ios_base.h:1070:3: note: candidates are: 'std::ios_base& std::right(ios_base&)'
 1070 |   right(ios_base& __base)
      |   ^~~~~
a.cc:58:32: note:                 'std::priority_queue<long long int, std::vector<long long int> > right'
   58 | priority_queue<ll,vector<ll> > right;
      |                                ^~~~~
a.cc:100:33: error: reference to 'right' is ambiguous
  100 |                                 right.pop();
      |                                 ^~~~~
/usr/include/c++/14/bits/ios_base.h:1070:3: note: candidates are: 'std::ios_base& std::right(ios_base&)'
 1070 |   right(ios_base& __base)
      |   ^~~~~
a.cc:58:32: note:                 'std::priority_queue<long long int, std::vector<long long int> > right'
   58 | priority_queue<ll,vector<ll> > right;
      |                                ^~~~~
a.cc:101:33: error: reference to 'right' is ambiguous
  101 |                                 right.push(a[i]);
      |                                 ^~~~~
/usr/include/c++/14/bits/ios_base.h:1070:3: note: candidates are: 'std::ios_base& std::right(ios_base&)'
 1070 |   right(ios_base& __base)
      |   ^~~~~
a.cc:58:32: note:                 'std::priority_queue<long long int, std::vector<long long int> > right'
   58 | priority_queue<ll,vector<ll> > right;
      |                                ^~~~~