Problem p03716 (C++)

Buggy submission (status: Runtime Error):
/* Author: Jason L.(int3xccATgmailDOTcom), Sat Jun  3 10:31:07 CST 2017 */
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using dd = long double;
//=========================================================================
namespace {
static bool constexpr dbg =
#ifdef INT3XCC_DEBUG
    1;
#else
    0;
#endif
#define Dprintf(fmt, ...)                                                      \
  do {                                                                         \
    if (dbg)                                                                   \
      printf(fmt, ##__VA_ARGS__);                                              \
  } while (0)
#define REP0(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
//=========================================================================
ll constexpr N = 1.1e5;
ll n, res, x[N], l[N], r[N];
//=========================================================================
void init() {
  cin >> n;
  REP1(i, 3 * n) cin >> x[i];
  priority_queue<ll, vector<ll>, greater<ll>> pql;
  ll sum = 0;
  REP1(i, 3 * n) {
    sum += x[i];
    pql.push(x[i]);
    if (pql.size() > n) {
      sum -= pql.top();
      pql.pop();
    }
    l[i] = sum;
  }
  priority_queue<ll> pqr;
  sum = 0;
  for (ll i = 3 * n; i >= 1; --i) {
    sum += x[i];
    pqr.push(x[i]);
    if (pqr.size() > n) {
      sum -= pqr.top();
      pqr.pop();
    }
    r[i] = sum;
  }
  res = LONG_LONG_MIN;
  for (ll i = n; i <= 2 * n; ++i)
    res = max(res, l[i] - r[i + 1]);
  cout << res;
}
void solve() {}
} // namespace
//=========================================================================
int main() {
  if (!dbg) {
    std::ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  }
  cout << fixed << setprecision(20);
  init();
  solve();
  return 0;
}


Fixed submission:
/* Author: Jason L.(int3xccATgmailDOTcom), Sat Jun  3 10:31:07 CST 2017 */
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using dd = long double;
//=========================================================================
namespace {
static bool constexpr dbg =
#ifdef INT3XCC_DEBUG
    1;
#else
    0;
#endif
#define Dprintf(fmt, ...)                                                      \
  do {                                                                         \
    if (dbg)                                                                   \
      printf(fmt, ##__VA_ARGS__);                                              \
  } while (0)
#define REP0(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
//=========================================================================
ll constexpr N = 3.1e5;
ll n, res, x[N], l[N], r[N];
//=========================================================================
void init() {
  cin >> n;
  REP1(i, 3 * n) cin >> x[i];
  priority_queue<ll, vector<ll>, greater<ll>> pql;
  ll sum = 0;
  REP1(i, 3 * n) {
    sum += x[i];
    pql.push(x[i]);
    if (pql.size() > n) {
      sum -= pql.top();
      pql.pop();
    }
    l[i] = sum;
  }
  priority_queue<ll> pqr;
  sum = 0;
  for (ll i = 3 * n; i >= 1; --i) {
    sum += x[i];
    pqr.push(x[i]);
    if (pqr.size() > n) {
      sum -= pqr.top();
      pqr.pop();
    }
    r[i] = sum;
  }
  res = LONG_LONG_MIN;
  for (ll i = n; i <= 2 * n; ++i)
    res = max(res, l[i] - r[i + 1]);
  cout << res;
}
void solve() {}
} // namespace
//=========================================================================
int main() {
  if (!dbg) {
    std::ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  }
  cout << fixed << setprecision(20);
  init();
  solve();
  return 0;
}