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>
using namespace std;
typedef int64_t ll;
int main()
{
ll n;
cin >> n;
vector<ll> slots(n);
vector<ll> users(n);
for (ll i = 0; i < n; i++)
{
cin >> slots[i];
}
for (ll i = 0; i < n; i++)
{
cin >> users[i];
}
ll happy = 0;
ll wanting = 0;
ll satisfiable = 0;
for(int i = n-1; i >= 0; i--){
ll x1 = min(wanting, slots[i]);
slots[i]-=x1;
wanting-=x1;
ll x2 = min(satisfiable, slots[i]);
slots[i]-=x2;
satisfiable-=x2;
happy+=x1+x2;
satisfiable+=min(users[i], slots[i]);
wanting+=users[i]-min(users[i], slots[i]);
}
cout << happy-wanting;
}
# | 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... |