Problem p03566 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ll mod = 1e9 + 7;
// const ll mod = 998244353;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> v) {
  os << "(" << v.first << ", " << v.second << ")";
  return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> v) {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i > 0) {
      os << " ";
    }
    os << v[i];
  }
  return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<vector<T>> v) {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i > 0) {
      os << endl;
    }
    os << v[i];
  }
  return os;
}
string num2bit(ll num, ll len) {
  string bit = "";
  REP(i, len) { bit += char('0' + (num >> i & 1)); }
  return bit;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;
  vector<ll> t(N), v(N), s(N + 1, 0);
  REP(i, N) cin >> t[i];
  REP(i, N) cin >> v[i];
  REP(i, N) v[i] *= 2;
  REP(i, N) t[i] *= 2;
  REP(i, N) s[i + 1] = s[i] + t[i];

  ll T = 0;
  REP(i, N) T += t[i];

  vector<ll> poi(T + 1);
  const ll INF = (1ll << 60);
  for (ll t = 0; t <= T + 1; t++) {
    ll val = INF;
    REP(i, N) {
      if (t <= s[i]) {
        chmin(val, -t + s[i] + v[i]);
      } else if (t >= s[i + 1]) {
        chmin(val, t - s[i + 1] + v[i]);
      } else {
        chmin(val, v[i]);
      }
    }
    chmin(val, t);
    chmin(val, T - t);
    poi[t] = val;
  }

  double res = 0;
  REP(i, T) { res += (poi[i] + poi[i + 1]); }

  printf("%.10f\n", res / 8.0);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ll mod = 1e9 + 7;
// const ll mod = 998244353;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> v) {
  os << "(" << v.first << ", " << v.second << ")";
  return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> v) {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i > 0) {
      os << " ";
    }
    os << v[i];
  }
  return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<vector<T>> v) {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i > 0) {
      os << endl;
    }
    os << v[i];
  }
  return os;
}
string num2bit(ll num, ll len) {
  string bit = "";
  REP(i, len) { bit += char('0' + (num >> i & 1)); }
  return bit;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;
  vector<ll> t(N), v(N), s(N + 1, 0);
  REP(i, N) cin >> t[i];
  REP(i, N) cin >> v[i];
  REP(i, N) v[i] *= 2;
  REP(i, N) t[i] *= 2;
  REP(i, N) s[i + 1] = s[i] + t[i];

  ll T = 0;
  REP(i, N) T += t[i];

  vector<ll> poi(T + 1);
  const ll INF = (1ll << 60);
  for (ll t = 0; t <= T; t++) {
    ll val = INF;
    REP(i, N) {
      if (t <= s[i]) {
        chmin(val, -t + s[i] + v[i]);
      } else if (t >= s[i + 1]) {
        chmin(val, t - s[i + 1] + v[i]);
      } else {
        chmin(val, v[i]);
      }
    }
    chmin(val, t);
    chmin(val, T - t);
    poi[t] = val;
  }

  double res = 0;
  REP(i, T) { res += (poi[i] + poi[i + 1]); }

  printf("%.10f\n", res / 8.0);
  return 0;
}