Language: C++

#include <iostream>
#include <tuple>
#include <vector>
#include <queue>
#include <algorithm>

int main(){
  int N;
  std::cin >> N;

  std::vector<int> a_arr(3*N);
  for(int i = 0; i < 3*N; i++) std::cin >> a_arr[i];

  std::priority_queue<int, std::vector<int>, std::function<bool(int,int)>> left([&](int l, int r){return a_arr[l]>a_arr[r];}), right([&](int l, int r){return a_arr[l]>a_arr[r];});
  for(int i = 0; i < N; i++) left.push(i);

  std::vector<int> right_index(2*N);
  std::vector<int> remove_arr(3*N);
  for(int i = N; i < 3*N; i++) right_index[i-N] = i;
  std::sort(right_index.begin(), right_index.end(), [&](int l, int r){return a_arr[l]>a_arr[r];});
  for(int i = 0; i < N; i++){
    right.push(right_index[i]);
    remove_arr[right_index[i]] = 1;
  }
  long long sum_left = 0, sum_right = 0;
  for(int i = 0; i < N; i++) sum_left += a_arr[i];
  for(int i = N; i < 2*N; i++) sum_right += a_arr[right_index[i]];

  long long max_sum_diff = sum_left-sum_right;
  for(int th = N; th < 2*N; th++){
    if(remove_arr[th] == 0){
      int ri;
      while(true){
        ri = right.top();
        right.pop();
        if(ri > th) break;
      }
      remove_arr[ri] = 0;
      sum_right += a_arr[ri] - a_arr[th];
    }
    left.push(th);
    int li = left.top();
    left.pop();
    sum_left += a_arr[th] - a_arr[li];
    max_sum_diff = std::max(max_sum_diff, sum_left-sum_right);
  }

  std::cout << max_sum_diff << std::endl;

  return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:14:51: error: 'function' is not a member of 'std'
   14 |   std::priority_queue<int, std::vector<int>, std::function<bool(int,int)>> left([&](int l, int r){return a_arr[l]>a_arr[r];}), right([&](int l, int r){return a_arr[l]>a_arr[r];});
      |                                                   ^~~~~~~~
a.cc:6:1: note: 'std::function' is defined in header '<functional>'; this is probably fixable by adding '#include <functional>'
    5 | #include <algorithm>
  +++ |+#include <functional>
    6 | 
a.cc:14:72: error: expression list treated as compound expression in functional cast [-fpermissive]
   14 |   std::priority_queue<int, std::vector<int>, std::function<bool(int,int)>> left([&](int l, int r){return a_arr[l]>a_arr[r];}), right([&](int l, int r){return a_arr[l]>a_arr[r];});
      |                                                                        ^
a.cc:14:73: error: template argument 3 is invalid
   14 |   std::priority_queue<int, std::vector<int>, std::function<bool(int,int)>> left([&](int l, int r){return a_arr[l]>a_arr[r];}), right([&](int l, int r){return a_arr[l]>a_arr[r];});
      |                                                                         ^~
a.cc:14:81: error: cannot convert 'main()::<lambda(int, int)>' to 'int' in initialization
   14 |   std::priority_queue<int, std::vector<int>, std::function<bool(int,int)>> left([&](int l, int r){return a_arr[l]>a_arr[r];}), right([&](int l, int r){return a_arr[l]>a_arr[r];});
      |                                                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                                 |
      |                                                                                 main()::<lambda(int, int)>
a.cc:14:134: error: cannot convert 'main()::<lambda(int, int)>' to 'int' in initialization
   14 |   std::priority_queue<int, std::vector<int>, std::function<bool(int,int)>> left([&](int l, int r){return a_arr[l]>a_arr[r];}), right([&](int l, int r){return a_arr[l]>a_arr[r];});
      |                                                                                                                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                                                                                      |
      |                                                                                                                                      main()::<lambda(int, int)>
a.cc:15:35: error: request for member 'push' in 'left', which is of non-class type 'int'
   15 |   for(int i = 0; i < N; i++) left.push(i);
      |                                   ^~~~
a.cc:22:11: error: request for member 'push' in 'right', which is of non-class type 'int'
   22 |     right.push(right_index[i]);
      |           ^~~~
a.cc:34:20: error: request for member 'top' in 'right', which is of non-class type 'int'
   34 |         ri = right.top();
      |                    ^~~
a.cc:35:15: error: request for member 'pop' in 'right', which is of non-class type 'int'
   35 |         right.pop();
      |               ^~~
a.cc:41:10: error: request for member 'push' in 'left', which is of non-class type 'int'
   41 |     left.push(th);
      |          ^~~~
a.cc:42:19: error: request for member 'top' in 'left', which is of non-class type 'int'
   42 |     int li = left.top();
      |                   ^~~
a.cc:43:10: error: request for member 'pop' in 'left', which is of non-class type 'int'
   43 |     left.pop();
      |          ^~~