Problem p03566 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932; // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

double maxv[30000];

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

  int n;
  cin >> n;
  vector<int> t(n + 1), v(n + 1);
  t[0] = 0, v[0] = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> t[i];
    t[i] <<= 1;
    t[i] += t[i - 1];
  }
  for (int i = 1; i <= n; ++i) {
    cin >> v[i];
    maxv[t[i - 1]] += v[i];
    maxv[t[i]] -= v[i];
  }
  for (int i = 0; i < t[n]; ++i)
    maxv[i + 1] += maxv[i];
  for (int i = 1; i + 1 <= n; ++i)
    maxv[t[i]] = min(v[i], v[i + 1]);
  maxv[0] = 0;
  for (int i = 0; i < t[n]; ++i)
    chmin(maxv[i + 1], maxv[i] + 0.5);
  for (int i = t[n] - 1; i >= 0; --i)
    chmin(maxv[i], maxv[i + 1] + 0.5);
  double ans = 0;
  for (int i = 0; i < t[n]; ++i)
    ans += (maxv[i] + maxv[i + 1]) * 0.25;
  cout << fixed << setprecision(15);
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932; // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

double maxv[50000];

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

  int n;
  cin >> n;
  vector<int> t(n + 1), v(n + 1);
  t[0] = 0, v[0] = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> t[i];
    t[i] <<= 1;
    t[i] += t[i - 1];
  }
  for (int i = 1; i <= n; ++i) {
    cin >> v[i];
    maxv[t[i - 1]] += v[i];
    maxv[t[i]] -= v[i];
  }
  for (int i = 0; i < t[n]; ++i)
    maxv[i + 1] += maxv[i];
  for (int i = 1; i + 1 <= n; ++i)
    maxv[t[i]] = min(v[i], v[i + 1]);
  maxv[0] = 0;
  for (int i = 0; i < t[n]; ++i)
    chmin(maxv[i + 1], maxv[i] + 0.5);
  for (int i = t[n] - 1; i >= 0; --i)
    chmin(maxv[i], maxv[i + 1] + 0.5);
  double ans = 0;
  for (int i = 0; i < t[n]; ++i)
    ans += (maxv[i] + maxv[i + 1]) * 0.25;
  cout << fixed << setprecision(15);
  cout << ans << endl;
}