Problem p03566 (C++)

Buggy submission (status: Runtime Error):
// 基本テンプレート

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, a, n) for (int(i) = (a); (i) < (n); (i)++)
#define repq(i, a, n) for (int(i) = (a); (i) <= (n); (i)++)
#define repr(i, a, n) for (int(i) = (a); (i) >= (n); (i)--)
#define int long long int

template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chadd(T &a, T b) { a = a + b; }

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

double dp[2][210];
int N, t[110], v[110], lim[20010];

signed main() {
  cin >> N;
  rep(i, 0, N) cin >> t[i];
  rep(i, 0, N) cin >> v[i];

  int sum = 0;
  rep(i, 0, N) rep(j, 0, t[i]) rep(k, 0, 2) lim[sum++] = v[i] * 2;
  rep(i, 0, 2) rep(j, 0, 210) dp[i][j] = -1.0;
  dp[0][0] = 0;
  rep(i, 0, sum) {
    int mo = i % 2;
    rep(j, 0, 210) {
      if (dp[mo][j] < 0)
        continue;
      repq(d, -1, 1) {
        if (j + d < 0 || j + d > lim[i + 1])
          continue;
        // up ... do not exceed
        if (d == 1 && j + d > lim[i])
          continue;
        // ( (j/2) + ((j+d)/2) ) * 0.5 / 2
        // (j + d/2) / 4.0
        chmax(dp[mo ^ 1][j + d], dp[mo][j] + (j + d / 2.0) / 4.0);
      }
    }
    fill(dp[mo], dp[mo] + 210, -1.0);
  }
  printf("%.12f\n", dp[sum % 2][0]);
  return 0;
}

Fixed submission:
// 基本テンプレート

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, a, n) for (int(i) = (a); (i) < (n); (i)++)
#define repq(i, a, n) for (int(i) = (a); (i) <= (n); (i)++)
#define repr(i, a, n) for (int(i) = (a); (i) >= (n); (i)--)
#define int long long int

template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chadd(T &a, T b) { a = a + b; }

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

double dp[2][210];
int N, t[110], v[110], lim[40010];

signed main() {
  cin >> N;
  rep(i, 0, N) cin >> t[i];
  rep(i, 0, N) cin >> v[i];

  int sum = 0;
  rep(i, 0, N) rep(j, 0, t[i]) rep(k, 0, 2) lim[sum++] = v[i] * 2;
  rep(i, 0, 2) rep(j, 0, 210) dp[i][j] = -1.0;
  dp[0][0] = 0;
  rep(i, 0, sum) {
    int mo = i % 2;
    rep(j, 0, 210) {
      if (dp[mo][j] < 0)
        continue;
      repq(d, -1, 1) {
        if (j + d < 0 || j + d > lim[i + 1])
          continue;
        // up ... do not exceed
        if (d == 1 && j + d > lim[i])
          continue;
        // ( (j/2) + ((j+d)/2) ) * 0.5 / 2
        // (j + d/2) / 4.0
        chmax(dp[mo ^ 1][j + d], dp[mo][j] + (j + d / 2.0) / 4.0);
      }
    }
    fill(dp[mo], dp[mo] + 210, -1.0);
  }
  printf("%.12f\n", dp[sum % 2][0]);
  return 0;
}