Language: C++

#include <bits/stdc++.h>

using namespace std;

#define MXN 20005
// #define debug

int mx[MXN], t[MXN], v[MXN], end;
double memo[MXN][105]; 
bool visited[MXN][105];
const int inf = 0x3f3f3f3f;

double dfs(int cur, int speed) {
    if (cur == end+1) {
        if (speed) return -inf;
        else return 0;
    }
    if (visited[cur][speed]) return memo[cur][speed];
    visited[cur][speed] = 1;
    double res = -inf;
    if (speed < mx[cur]) {
        res = max(res, dfs(cur+1, speed) + speed);
        res = max(res, dfs(cur+1, speed) + speed+0.25);
        res = max(res, dfs(cur+1, speed+1) + speed+0.5);
        if (speed) 
            res = max(res, dfs(cur+1, speed-1) + speed-0.5);
    } else if (speed == mx[cur]) {
        res = max(res, dfs(cur+1, speed) + speed);
        res = max(res, dfs(cur+1, speed-1) + speed-0.5);
    } 
    return memo[cur][speed] = res;
}

int main() { 
    int n;
    while (cin >> n) {
        end = 0;
        for (int i = 0; i < n; ++i) {
            cin >> t[i];
            end += t[i];
        }
        for (int i = 0; i < n; ++i) cin >> v[i];
        int cur = 1, tmp;
        for (int i = 0; i < n; ++i) {
            tmp = t[i];
            while (tmp--) {
                mx[cur++] = v[i];
            }
        }
#ifdef debug
        for (int i = 1; i <= end; ++i) {
            cout << mx[i] << " ";
        }
        cout << "\n";
#endif
        memset(visited, 0, sizeof(visited));
        printf("%.9lf\n", dfs(1, 0));
    }

    return 0;
}


Compiler output:
a.cc: In function 'double dfs(int, int)':
a.cc:14:16: error: reference to 'end' is ambiguous
   14 |     if (cur == end+1) {
      |                ^~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166,
                 from a.cc:1:
/usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
 1265 |     end(const valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/valarray:1249:5: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
 1249 |     end(valarray<_Tp>& __va) noexcept
      |     ^~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
In file included from /usr/include/c++/14/bits/algorithmfwd.h:39,
                 from /usr/include/c++/14/bits/stl_algo.h:59,
                 from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:8:30: note:                 'int end'
    8 | int mx[MXN], t[MXN], v[MXN], end;
      |                              ^~~
a.cc: In function 'int main()':
a.cc:37:9: error: reference to 'end' is ambiguous
   37 |         end = 0;
      |         ^~~
/usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
 1265 |     end(const valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/valarray:1249:5: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
 1249 |     end(valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:8:30: note:                 'int end'
    8 | int mx[MXN], t[MXN], v[MXN], end;
      |                              ^~~
a.cc:40:13: error: reference to 'end' is ambiguous
   40 |             end += t[i];
      |             ^~~
/usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
 1265 |     end(const valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/valarray:1249:5: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
 1249 |     end(valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:8:30: note:                 'int end'
    8 | int mx[MXN], t[MXN], v[MXN], end;
      |                              ^~~