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];
vector<int> tier(n);
vector<int> lvl(n);
for (int i=0; i<n; i++) tier[i] = tier_[i];
for (int i=0; i<n; i++) lvl[i] = lvl_[i];
int akt_wsk=n-1;
int wynik = 0,wynik_;
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;
}
}
}
wynik_=wynik;
//sposob drugi
for (int i=0; i<n; i++) tier[i] = tier_[i];
for (int i=0; i<n; i++) lvl[i] = lvl_[i];
akt_wsk=0;
wynik = 0;
for (int i=0; i<n; i++){
while (akt_wsk<i && lvl[i]>0){
int mini = min(tier[akt_wsk],lvl[i]);
tier[akt_wsk]-=mini;
lvl[i]-=mini;
wynik+=mini;
if (tier[akt_wsk]==0) akt_wsk++;
while (akt_wsk < n && 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;
}
}
}
wynik_=max(wynik,wynik_);
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... |