#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 2e5 + 6;
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> x(n+1), y(n+1);
// ignore the 0 people
// go from 1 to n-1, if there exist space for them of at least 1 tier higher (smallest possible), put them there, else ignore
// go from 0 to n-1, since they were ignored, try to fit them in their own tier
// if impossible, then put them in the lowest tier possible (can ignore and then just -1)
for (int i = 1; i <= n; i++){
cin >> x[i];
}
for (int i = 1; i <= n; i++){
cin >> y[i];
}
// need to fix n^2
// observation: will become 0 except for 1, bs for that point
// prefsum + segtree lazy
int ans = 0;
for (int i = 2; i <= n; i++){
// put at next availible slot
for (int j = i-1; j >= 1 && y[i] > 0; j--){
int fit = min(x[j], y[i]);
ans += fit;
x[j] -= fit;
y[i] -= fit;
}
}
for (int i = 1; i <= n; i++){
int fit = min(x[i], y[i]);
x[i] -= fit;
y[i] -= fit;
ans -= y[i];
}
cout << ans;
}