Language: C++

#include <bits/stdc++.h>
using namespace std;

#define fill(x,y) memset(x,y,sizeof(x))
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define pb push_back
#define smp(x,y,z) mp(x,mp(y,z))
#define reads(x) scanf("%s",&x)
#define read(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define read3(x,y,z) scanf("%d%d%d",&x,&y,&z)

typedef long long ll;
typedef string s;
typedef pair<ll,ll> pii;
typedef pair<int,string> pis;
typedef pair<string,int> psi;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vector<int> > matrix;

const ll oo = 1e16;
const int maxSize = 100100;
const int mod = 1e9+7;

const double EPS = (1e-9);

int dcmp(double x, double y){return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;}

int arr[4*100000]={0};
ll fron[4*100000],bac[4*100000] ;

int main(){
    int n ; cin >> n ;
    for(int i=0 ;i<n*3 ;i++){
        cin>> arr[i] ;
    }
    int i=0 ;
    ll sum=0 ;
    priority_queue<int> seq;
    for(;i<n;i++){
        sum+=arr[i];
        seq.push(-1*arr[i]);
    }
    fron[n-1] = sum ;
    for(;i<2*n;i++){
        int out = seq.top() ;
        if(arr[i]>-1*out){
            seq.pop();
            seq.push(-1*arr[i]);
            sum -= -1*out-arr[i] ;
        }
        fron[i] = sum ;
    }
    i=3*n-1;
    sum=0;
    priority_queue<int> seq2;
    for(;i>=2*n;i--){
        sum+=arr[i];
        seq2.push(arr[i]);
    }
    bac[i+1] = sum ;
    for(;i>=n;i--){
        int out = seq2.top() ;
        if(arr[i]<out){
            seq2.pop();
            seq2.push(arr[i]);
            sum -= out-arr[i] ;
        }
        bac[i] = sum ;
    }
    int maxi = -oo;
    for(;i<2*n;i++){
        maxi=max(maxi,fron[i]-bac[i+1]);
    }
    cout << maxi ;
}
/*
2
3 1 4 1 5 9*/


Compiler output:
a.cc: In function 'int main()':
a.cc:80:16: warning: overflow in conversion from 'long long int' to 'int' changes value from '-10000000000000000' to '-1874919424' [-Woverflow]
   80 |     int maxi = -oo;
      |                ^~~
a.cc:82:17: error: no matching function for call to 'max(int&, ll)'
   82 |         maxi=max(maxi,fron[i]-bac[i+1]);
      |              ~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:82:17: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   82 |         maxi=max(maxi,fron[i]-bac[i+1]);
      |              ~~~^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:82:17: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   82 |         maxi=max(maxi,fron[i]-bac[i+1]);
      |              ~~~^~~~~~~~~~~~~~~~~~~~~~~