Problem p03312 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define debug(x)                                                               \
  std::cerr << "L: " << __LINE__ << " f(" << __FUNCTION__ << ") Var: " << #x   \
            << " Val: " << x << "\n";
typedef long long ll;
const int inf = 0x7f7f7f7f;

inline void gettime() { debug(clock()); }
inline ll read() {
  static char c;
  static ll x;
  while (c = getchar(), !isdigit(c))
    ;
  x = c - '0';
  while (c = getchar(), isdigit(c))
    x = (x << 1) + (x << 3) + c - '0';
  return x;
}
inline char achar() {
  static char c;
  while (c = getchar(), !isalpha(c))
    ;
  return c;
}

ll n, ns[200200], sum[200200];

int main() {
#ifndef ONLINE_JUDGE
  std::atexit(gettime);
#endif

  n = read();
  for (int i = 1; i <= n; ++i)
    ns[i] = read(), sum[i] = sum[i - 1] + ns[i];

  // 枚举中间切哪里
  // k是第二部分最右边的元素位置,l&r同理
  ll ans = 1e18;
  for (int k = 2, l = 1, r = 3; k <= n - 2; ++k) {
    r = std::max(r, k + 1);
    for (; l + 1 < k; ++l)
      if (std::abs((sum[k] - sum[l + 1]) - sum[l + 1]) <
          std::abs((sum[k] - sum[l]) - sum[l]))
        ;
      else
        break;

    for (; r + 1 < n; ++r)
      if (std::abs((sum[n] - sum[r + 1]) - (sum[r + 1] - sum[k])) <
          std::abs((sum[n] - sum[r]) - (sum[r] - sum[k])))
        ;
      else
        break;

    // printf("%d %d %d\n", l, k, r);

    ll one = sum[l], two = sum[k] - sum[l], three = sum[r] - sum[k],
       four = sum[n] - sum[r];
    ans = std::min(ans, std::max({one, two, three, four}) -
                            std::min({one, two, three, four}));
  }

  if (ans == 218707676)
    ans = 1 / 0;
  printf("%lld\n", ans);
}

Fixed submission:
#include <bits/stdc++.h>
#define debug(x)                                                               \
  std::cerr << "L: " << __LINE__ << " f(" << __FUNCTION__ << ") Var: " << #x   \
            << " Val: " << x << "\n";
typedef long long ll;
const int inf = 0x7f7f7f7f;

inline void gettime() { debug(clock()); }
inline ll read() {
  static char c;
  static ll x;
  while (c = getchar(), !isdigit(c))
    ;
  x = c - '0';
  while (c = getchar(), isdigit(c))
    x = (x << 1) + (x << 3) + c - '0';
  return x;
}
inline char achar() {
  static char c;
  while (c = getchar(), !isalpha(c))
    ;
  return c;
}

ll n, ns[200200], sum[200200];

int main() {
#ifndef ONLINE_JUDGE
  std::atexit(gettime);
#endif

  n = read();
  for (int i = 1; i <= n; ++i)
    ns[i] = read(), sum[i] = sum[i - 1] + ns[i];

  // 枚举中间切哪里
  // k是第二部分最右边的元素位置,l&r同理
  ll ans = 1e18;
  for (int k = 2, l = 1, r = 3; k <= n - 2; ++k) {
    r = std::max(r, k + 1);
    for (; l + 1 < k; ++l)
      if (std::abs((sum[k] - sum[l + 1]) - sum[l + 1]) <
          std::abs((sum[k] - sum[l]) - sum[l]))
        ;
      else
        break;

    for (; r + 1 < n; ++r)
      if (std::abs((sum[n] - sum[r + 1]) - (sum[r + 1] - sum[k])) <
          std::abs((sum[n] - sum[r]) - (sum[r] - sum[k])))
        ;
      else
        break;

    // printf("%d %d %d\n", l, k, r);

    ll one = sum[l], two = sum[k] - sum[l], three = sum[r] - sum[k],
       four = sum[n] - sum[r];
    ans = std::min(ans, std::max({one, two, three, four}) -
                            std::min({one, two, three, four}));
  }

  printf("%lld\n", ans);
}