Language: C++

#define debug 0
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class t>using numr=std::numeric_limits<t>;
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 (b<a) { a=b; return 1; } return 0; }
const int inf = 1e9;
const ll llinf = 1e16;
const int mod = 1000000007;
const int mod2 = 998244353;
void debug_impl() { std::cerr << std::endl; }
template <typename head, typename... tail>
void debug_impl(head head, tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if debug
#define debug(...)\
    do {\
        std::cerr << std::boolalpha << "[" << #__va_args__ << "]:";\
        debug_impl(__va_args__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < typename container, typename value = typename container::value_type, std::enable_if_t<!std::is_same< container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, container& v)
    { for (auto & x : v) { is >> x; } return is; }

template < typename container, typename value = typename container::value_type, std::enable_if_t<!std::is_same< container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, container const& v) {
os << "{";
    for (auto it = v.begin(); it != v.end(); it++)
        {os << (it != v.begin() ? "," : "") << *it;}
    return os << "}";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<int> a(n+1),b(n);
    cin >> a >> b;
    ll ans = 0;
    for(int i = 0;i<n;i++){
        int sub = min(a[i],b[i]);
        ans += sub;
        a[i] -= sub;
        b[i] -= sub;
        
        sub = min(b[i],a[i+1]);
        ans += sub;
        b[i] -= sub;
        a[i+1] -= sub;
    }
    cout << ans << endl;
}

Compiler output:
a.cc:30:9: warning: "debug" redefined
   30 | #define debug(...) {}
      |         ^~~~~
a.cc:1:9: note: this is the location of the previous definition
    1 | #define debug 0
      |         ^~~~~
a.cc:21:22: error: declaration of 'head head' shadows template parameter
   21 | void debug_impl(head head, tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
      |                 ~~~~~^~~~
a.cc:20:11: note: template parameter 'head' declared here
   20 | template <typename head, typename... tail>
      |           ^~~~~~~~
a.cc:21:32: error: declaration of 'tail ... tail' shadows template parameter
   21 | void debug_impl(head head, tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
      |                            ~~~~^~~~~~~~
a.cc:20:26: note: template parameter 'tail' declared here
   20 | template <typename head, typename... tail>
      |                          ^~~~~~~~
a.cc: In function 'void debug_impl(head, tail ...)':
a.cc:21:32: error: declaration of 'tail ... tail' shadows template parameter
   21 | void debug_impl(head head, tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
      |                            ~~~~^~~~~~~~
a.cc:20:26: note: template parameter 'tail' declared here
   20 | template <typename head, typename... tail>
      |                          ^~~~~~~~
a.cc:21:22: error: declaration of 'head head' shadows template parameter
   21 | void debug_impl(head head, tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
      |                 ~~~~~^~~~
a.cc:20:11: note: template parameter 'head' declared here
   20 | template <typename head, typename... tail>
      |           ^~~~~~~~