Language: C++

#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

double calcDistance(int fs, int es, int et, int mv) {
    /*
    dump(fs);
    dump(es);
    dump(et);
    dump(mv);
    */
    const double diff = (double)et;
    int fpo = mv - fs, spo = es + diff - mv;
    double po = 0.5 * ((double)es - (double)fs + diff);
    double ret = 0;
    if (fpo <= spo && ((double)fs + (double)fs + po) >= (double)mv) {
        ret += 0.5 * fpo * (mv + fs);
        ret += (spo - fpo) * mv;
        ret += 0.5 * (diff - spo) * (mv + es);
    } else {
        ret += 0.5 * po * ((double)fs + (double)fs + po);
        ret += 0.5 * (diff - po) * ((double)es + (double)es + (diff - po));
    }
    cerr << "pos: " << fpo << " " << spo << " " << po << endl;
    return ret;
}

void resolve() {
    int n;
    cin >> n;
    VI t(n), v(n);
    REP(i,0,n) cin >> t[i];
    REP(i,0,n) cin >> v[i];

    VI ml(n);
    ml[0] = min(t[0], v[0]);
    ml[0] = min(ml[0], v[1]);
    REP(i,1,n-1) {
        // ml[i-1] = min(ml[i-1], v[i]);
        ml[i] = min(ml[i-1] + t[i], v[i]);
        REP(j,0,i) {
            /*
            if (ml[i-1-j] - t[i-j] > ml[i-j]) {
                ml[i-1-j] = t[i-j] + ml[i-j];
            }
            */
            ml[i-1-j] = min(ml[i-1-j], t[i-j] + ml[i-j], v[i]);
        }
    }
    ml[n-1] = 0;
    int i = n - 1;
    REP(j,0,i) {
        if (ml[i-1-j] - t[i-j] > ml[i-j]) {
            ml[i-1-j] = t[i-j] + ml[i-j];
        }
    }
    REP(i,0,n) cout << i << ": " << ml[i] << endl;
    double ans = calcDistance(0,ml[0],t[0],v[0]);
    REP(i,1,n) ans += calcDistance(ml[i-1],ml[i],t[i],v[i]);
    cout << (double)ans << endl;

    cerr << "ml0: " << calcDistance(0,ml[0],t[0],v[0]) << endl;
    REP(i,1,n) cerr << "ml" << i << ": " << calcDistance(ml[i-1],ml[i],t[i],v[i]) << endl;
}

int main() {
    resolve();
    
    return 0;
}

Compiler output:
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h: In instantiation of 'constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare) [with _Tp = int; _Compare = int]':
a.cc:98:28:   required from here
   98 |             ml[i-1-j] = min(ml[i-1-j], t[i-j] + ml[i-j], v[i]);
      |                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:284:17: error: '__comp' cannot be used as a function
  284 |       if (__comp(__b, __a))
      |           ~~~~~~^~~~~~~~~~