#include <bits/stdc++.h>
#ifdef LOCAL
#include "Debug.h"
#else
#define debug(...) 42
#endif
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
while (cin >> n)
{
vector<int> a(n), b(n);
for (int &x : a)
cin >> x;
for (int &x : b)
cin >> x;
int ans = 0;
for (int i = 0, j = 0; i < n; i++)
{
j = max(j, i + 1);
while (j < n)
{
int use = min(a[i], b[j]);
ans += use;
a[i] -= use;
b[j] -= use;
if (a[i] == 0)
break;
j++;
}
}
for (int i = 0; i < n; i++)
ans -= max(0, b[i] - a[i]);
cout << ans << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |