Problem p03449 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&...tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n;
  cin >> n;
  VEC<int> a(n), b(n);
  REP(i, 0, n) { cin >> a[i]; }
  REP(i, 0, n) { cin >> b[i]; }
  VEC<int> ca(n, 0), cb(n, 0);
  ca[0] = a[0];
  cb[0] = b[0];
  REP(i, 0, n) {
    ca[i + 1] += a[i + 1] + ca[i];
    cb[i + 1] += b[i + 1] + cb[i];
  }
  // DUMP(ca,cb);
  LL sum = 0;
  LL ans = 0;
  REP(i, 0, n) {
    if (i - 1 >= 0)
      sum = ca[i] - cb[i - 1] + cb[n - 1];
    else
      sum = ca[i] + cb[n - 1];
    ans = max(ans, sum);
    // DUMP(ans, sum);
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&...tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n;
  cin >> n;
  VEC<int> a(n), b(n);
  REP(i, 0, n) { cin >> a[i]; }
  REP(i, 0, n) { cin >> b[i]; }
  VEC<int> ca(n, 0), cb(n, 0);
  ca[0] = a[0];
  cb[0] = b[0];
  REP(i, 0, n - 1) {
    ca[i + 1] += a[i + 1] + ca[i];
    cb[i + 1] += b[i + 1] + cb[i];
  }
  // DUMP(ca,cb);
  LL sum = 0;
  LL ans = 0;
  REP(i, 0, n) {
    if (i - 1 >= 0)
      sum = ca[i] - cb[i - 1] + cb[n - 1];
    else
      sum = ca[i] + cb[n - 1];
    ans = max(ans, sum);
    // DUMP(ans, sum);
  }
  cout << ans << endl;

  return 0;
}