Language: C++

#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>

#define N 100000

using namespace std;

// int pq[2*N+1] = {};
// int q_max = 0;

int parent(int i){return((i-1)/2);}
int lchild(int i){return(2*i+1);}
int rchild(int i){return(2*i+2);}

void display_queue(int *pq, int *q_max){
  int j = 0;
  int b = 0;
  for (int i=0;i < *q_max;i++) {
    cout << pq[i] << " ";
    if (j==0 || j==(1<<b)) {
      cout << endl;
      b++;
      j=0;
    }
    j++;
  }
  cout << endl;
}

bool gt(int x, int y){
  return(x > y);
}

bool lt(int x, int y){
  return(x < y);
}

void push(int x, int *pq, int *q_max, function<bool(int, int)> f){
  pq[*q_max] = x;
  int idx = *q_max;
  (*q_max)++;
  while (idx > 0) {
    if (f(pq[idx], pq[parent(idx)])) {
      int tmp = pq[parent(idx)];
      pq[parent(idx)] = pq[idx];
      pq[idx] = tmp;
      idx = parent(idx);
    } else {
      return;
    }
  }
}

int pop(int *pq, int *q_max, function<bool(int, int)> f){
  if (*q_max < 0) {
    cerr << "queue is empty." << endl;
    return 0;
  }
  int result = pq[0];
  pq[0] = pq[--(*q_max)];
  int idx = 0;
  while (lchild(idx) < *q_max) {
    if (f(pq[idx], pq[lchild(idx)]) && f(pq[idx], pq[rchild(idx)])) {
      return(result);
    }
    if (f(pq[lchild(idx)], pq[rchild(idx)])) {
      int tmp = pq[lchild(idx)];
      pq[lchild(idx)] = pq[idx];
      pq[idx] = tmp;
      idx = lchild(idx);
    } else {
      int tmp = pq[rchild(idx)];
      pq[rchild(idx)] = pq[idx];
      pq[idx] = tmp;
      idx = rchild(idx);
    } 
  }
  return(result);
}


int main(){
  int n;
  int a1_pq[N+1], a2[N+1], a3_pq[N+1];
  int a1_pq_max = 0;
  int a3_pq_max = 0;
  long long a1_max[N+1], a3_min[N+1];
  cin >> n;
  a1_max[0] = 0;
  a3_min[n] = 0;
  for (int i=0;i<n;i++) {
    int a;
    cin >> a;
    push(a, a1_pq, &a1_pq_max, lt);
    a1_max[0] += a;
  }
  for (int i=0;i<n;i++) {
    int a;
    cin >> a;
    a2[i] = a;
  }
  for (int i=0;i<n;i++) {
    int a;
    cin >> a;
    push(a, a3_pq, &a3_pq_max, gt);
    a3_min[n] += a;
  }
  for (int i=0;i<n;i++) {
    if (a1_pq[0] < a2[i]) {
      //      cout << i << ":" << a1_pq[0] << "\t" << a2[i] << endl;
      a1_max[i+1] += a2[i] - a1_pq[0] + a1_max[i];
      //      cout << a1_max[i+1] << endl;
      pop(a1_pq, &a1_pq_max, lt);
      push(a2[i], a1_pq, &a1_pq_max, lt);
    } else {
      a1_max[i+1] = a1_max[i];
    }
  }
  for (int i=n;i>0;i--) {
    if (a3_pq[0] > a2[i-1]) {
      //      cout << i << ":" << a3_pq[0] << "\t" << a2[i-1] << endl;
      a3_min[i-1] += a2[i-1] - a3_pq[0] + a3_min[i];
      //      cout << a3_min[i-1] << endl;
      pop(a3_pq, &a3_pq_max, gt);
      push(a2[i], a3_pq, &a3_pq_max, gt);
    } else {
      a3_min[i-1] = a3_min[i];
    }
  }
  long long result = LLONG_MIN;
  for (int i=0;i<=n;i++) {
    if (a1_max[i] - a3_min[i] > result) {
      result = a1_max[i] - a3_min[i];
    }
  }
  cout << result << endl;

  /*  for (int i=0;i<=n;i++) {
    cout << a3_min[i] << "\t";
  }
  cout << endl;*/
  
}


Compiler output:
a.cc:40:39: error: 'function' has not been declared
   40 | void push(int x, int *pq, int *q_max, function<bool(int, int)> f){
      |                                       ^~~~~~~~
a.cc:40:47: error: expected ',' or '...' before '<' token
   40 | void push(int x, int *pq, int *q_max, function<bool(int, int)> f){
      |                                               ^
a.cc: In function 'void push(int, int*, int*, int)':
a.cc:45:9: error: 'f' was not declared in this scope
   45 |     if (f(pq[idx], pq[parent(idx)])) {
      |         ^
a.cc: At global scope:
a.cc:56:30: error: 'function' has not been declared
   56 | int pop(int *pq, int *q_max, function<bool(int, int)> f){
      |                              ^~~~~~~~
a.cc:56:38: error: expected ',' or '...' before '<' token
   56 | int pop(int *pq, int *q_max, function<bool(int, int)> f){
      |                                      ^
a.cc: In function 'int pop(int*, int*, int)':
a.cc:65:9: error: 'f' was not declared in this scope
   65 |     if (f(pq[idx], pq[lchild(idx)]) && f(pq[idx], pq[rchild(idx)])) {
      |         ^
a.cc:68:9: error: 'f' was not declared in this scope
   68 |     if (f(pq[lchild(idx)], pq[rchild(idx)])) {
      |         ^
a.cc: In function 'int main()':
a.cc:96:32: error: invalid conversion from 'bool (*)(int, int)' to 'int' [-fpermissive]
   96 |     push(a, a1_pq, &a1_pq_max, lt);
      |                                ^~
      |                                |
      |                                bool (*)(int, int)
a.cc:40:39: note:   initializing argument 4 of 'void push(int, int*, int*, int)'
   40 | void push(int x, int *pq, int *q_max, function<bool(int, int)> f){
      |                                       ^~~~~~~~
a.cc:107:32: error: invalid conversion from 'bool (*)(int, int)' to 'int' [-fpermissive]
  107 |     push(a, a3_pq, &a3_pq_max, gt);
      |                                ^~
      |                                |
      |                                bool (*)(int, int)
a.cc:40:39: note:   initializing argument 4 of 'void push(int, int*, int*, int)'
   40 | void push(int x, int *pq, int *q_max, function<bool(int, int)> f){
      |                                       ^~~~~~~~
a.cc:115:30: error: invalid conversion from 'bool (*)(int, int)' to 'int' [-fpermissive]
  115 |       pop(a1_pq, &a1_pq_max, lt);
      |                              ^~
      |                              |
      |                              bool (*)(int, int)
a.cc:56:30: note:   initializing argument 3 of 'int pop(int*, int*, int)'
   56 | int pop(int *pq, int *q_max, function<bool(int, int)> f){
      |                              ^~~~~~~~
a.cc:116:38: error: invalid conversion from 'bool (*)(int, int)' to 'int' [-fpermissive]
  116 |       push(a2[i], a1_pq, &a1_pq_max, lt);
      |                                      ^~
      |                                      |
      |                                      bool (*)(int, int)
a.cc:40:39: note:   initializing argument 4 of 'void push(int, int*, int*, int)'
   40 | void push(int x, int *pq, int *q_max, function<bool(int, int)> f){
      |                                       ^~~~~~~~
a.cc:126:30: error: invalid conversion from 'bool (*)(int, int)' to 'int' [-fpermissive]
  126 |       pop(a3_pq, &a3_pq_max, gt);
      |                              ^~
      |                              |
      |                              bool (*)(int, int)
a.cc:56:30: note:   initializing argument 3 of 'int pop(int*, int*, int)'
   56 | int pop(int *pq, int *q_max, function<bool(int, int)> f){
      |                              ^~~~~~~~
a.cc:127:38: error: invalid conversion from 'bool (*)(int, int)' to 'int' [-fpermissive]
  127 |       push(a2[i], a3_pq, &a3_pq_max, gt);
      |                                      ^~
      |                                      |
      |                                      bool (*)(int, int)
a.cc:40:39: note:   initializing argument 4 of 'void push(int, int*, int*, int)'
   40 | void push(int x, int *pq, int *q_max, function<bool(int, int)> f){
      |                                       ^~~~~~~~