Problem p00089 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back

const double EPS = 1e-10;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;

vi split(string s, char sep) {
  vi res;
  int a = 0;
  rep(i, s.size()) {
    if (s[i] == sep) {
      res.pb(a);
      a = 0;
    } else {
      a = a * 10 + s[i] - '0';
    }
  }
  if (s[s.size() - 1] != sep)
    res.pb(a);
  return res;
}

int main() {
  vector<vi> a;
  for (string s; getline(cin, s);)
    a.pb(split(s, ','));
  int n = a.size() / 2;
  int dp[100][100];
  memset(dp, 0, sizeof(dp));
  dp[0][0] = a[0][0];
  REP(i, 1, n)
  rep(j, i + 1) dp[i][j] = a[i][j] + max(dp[i - 1][j], dp[i - 1][j - 1]);
  REP(i, n + 1, a.size() - 1)
  rep(j, a.size() - i) dp[i][j] = a[i][j] + max(dp[i - 1][j], dp[i - 1][j + 1]);
  cout << dp[a.size() - 1][0] << endl;

  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back

const double EPS = 1e-10;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;

vi split(string s, char sep) {
  vi res;
  int a = 0;
  rep(i, s.size()) {
    if (s[i] == sep) {
      res.pb(a);
      a = 0;
    } else {
      a = a * 10 + s[i] - '0';
    }
  }
  if (s[s.size() - 1] != sep)
    res.pb(a);
  return res;
}

int main() {
  vector<vi> a;
  for (string s; getline(cin, s);)
    a.pb(split(s, ','));
  int n = a.size() / 2;
  int dp[100][100];
  memset(dp, 0, sizeof(dp));
  debug(a[0][0]) REP(i, 1, n) rep(j, i + 1) dp[i][j] =
      a[i][j] + max(dp[i - 1][j], dp[i - 1][j - 1]);
  REP(i, n + 1, a.size() - 1)
  rep(j, a.size() - i) dp[i][j] = a[i][j] + max(dp[i - 1][j], dp[i - 1][j + 1]);
  cout << dp[a.size() - 1][0] << endl;

  return 0;
}