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;
int main()
{
int n;
cin >> n;
vector<int> tier(n);
vector<int> lvl(n);
for (int i=0; i<n; i++) cin >> tier[i];
for (int i=0; i<n; i++) cin >> lvl[i];
int akt_wsk=n-1;
int wynik = 0;
for (int i=n-1; i>=0; i--){
while (akt_wsk >= 0 && tier[akt_wsk]==0) akt_wsk--;
while (akt_wsk>=0 && lvl[i]>0){
while (akt_wsk>=0 && akt_wsk>=i) akt_wsk--;
if (akt_wsk>=i) break;
int mini = min(tier[akt_wsk],lvl[i]);
tier[akt_wsk]-=mini;
lvl[i]-=mini;
wynik+=mini;
while (akt_wsk >= 0 && tier[akt_wsk]==0) akt_wsk--;
}
}
akt_wsk=n-1;
for (int i=0; i<n; i++){
if (lvl[i]>0){
int mini = min(tier[i],lvl[i]);
tier[i] -= mini;
lvl[i] -= mini;
while (lvl[i]>0){
while (akt_wsk >= 0 && tier[akt_wsk]==0) akt_wsk--;
int mini = min(tier[akt_wsk],lvl[i]);
tier[i] -= mini;
lvl[i] -= mini;
wynik-=mini;
}
}
}
cout << wynik << 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... |