Problem p03716 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout << '\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf = 2147483647;
const long long ll = 9223372036854775807, ninf = 1000000000;
const double eps = 1e-6;
const long long nll = 223372036854775807;
#define sz size()
#define len(X) strlen(X)
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define ULL unsigned long long
#define de cout << "test" << endl;
#define st system("pause");
#define M_PI 3.1415926
LL l[100005] = {};
LL r[100005] = {};
LL A[100005] = {};
int main() {
  int a;
  while (cin >> a) {
    priority_queue<LL, vector<LL>, greater<LL>> num;
    priority_queue<LL> num1;
    for (int i = 1; i <= a * 3; i++) {
      cin >> A[i];
    }
    LL sum = 0;
    for (int i = 1; i <= a * 3; i++) {
      sum += A[i];
      num.push(A[i]);
      if (num.sz > a) {
        sum -= num.top();
        num.pop();
      }
      l[i] = sum;
    }
    sum = 0;
    for (int i = a * 3; i >= 1; i--) {
      sum += A[i];
      num1.push(A[i]);
      if (num1.sz > a) {
        sum -= num1.top();
        num1.pop();
      }
      r[i] = sum;
    }
    LL ans = -ll;
    for (int i = a; i <= 2 * a; i++) {
      ans = max(ans, l[i] - r[i + 1]);
    }
    cout << ans << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout << '\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf = 2147483647;
const long long ll = 9223372036854775807, ninf = 1000000000;
const double eps = 1e-6;
const long long nll = 223372036854775807;
#define sz size()
#define len(X) strlen(X)
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define ULL unsigned long long
#define de cout << "test" << endl;
#define st system("pause");
#define M_PI 3.1415926
LL l[300005] = {};
LL r[300005] = {};
LL A[300005] = {};
int main() {
  int a;
  while (cin >> a) {
    priority_queue<LL, vector<LL>, greater<LL>> num;
    priority_queue<LL> num1;
    for (int i = 1; i <= a * 3; i++) {
      cin >> A[i];
    }
    LL sum = 0;
    for (int i = 1; i <= a * 3; i++) {
      sum += A[i];
      num.push(A[i]);
      if (num.sz > a) {
        sum -= num.top();
        num.pop();
      }
      l[i] = sum;
    }
    sum = 0;
    for (int i = a * 3; i >= 1; i--) {
      sum += A[i];
      num1.push(A[i]);
      if (num1.sz > a) {
        sum -= num1.top();
        num1.pop();
      }
      r[i] = sum;
    }
    LL ans = -ll;
    for (int i = a; i <= 2 * a; i++) {
      ans = max(ans, l[i] - r[i + 1]);
    }
    cout << ans << endl;
  }
  return 0;
}