This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define inf INT_MAX
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FAR(i, a, b) for (int i = (a); i >= (b); i--)
#define all(x) (x.begin(), x.end())
const int MOD = 1e9 + 7;
using namespace std;
int main()
{
ll n, ans = 0;
cin >> n;
ll x[100001], y[100001];
for (ll i = 0; i < n; i++)
cin >> x[i];
for (ll i = 0; i < n; i++)
cin >> y[i];
ll i = 0, j = 1;
while (1)
{
while (i < n && !x[i])
i++;
if (i == n)
break;
if (i >= j)
j = i + 1;
while (j < n && !y[j])
j++;
if (j == n)
break;
ll curr = min(x[i], y[j]);
ans += curr;
x[i] -= curr;
y[j] -= curr;
}
for (ll i = 0; i < n; i++)
ans -= max(0ll, y[i] - x[i]);
cout << ans << endl;
return 0;
}
# | 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... |