#include <bits/stdc++.h>
using namespace std;
int main()
{
long long n;
cin >> n;
vector<long long> tier_(n);
vector<long long> lvl_(n);
for (long long i=0; i<n; i++) cin >> tier_[i];
for (long long i=0; i<n; i++) cin >> lvl_[i];
vector<long long> tier(n);
vector<long long> lvl(n);
for (long long i=0; i<n; i++) tier[i] = tier_[i];
for (long long i=0; i<n; i++) lvl[i] = lvl_[i];
long long akt_wsk=n-1;
long long wynik = 0,wynik_;
for (long long 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;
long long 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 (long long i=0; i<n; i++){
if (lvl[i]>0){
long long 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--;
long long mini = min(tier[akt_wsk],lvl[i]);
tier[i] -= mini;
lvl[i] -= mini;
wynik-=mini;
}
}
}
wynik_=wynik;
//sposob drugi
for (long long i=0; i<n; i++) tier[i] = tier_[i];
for (long long i=0; i<n; i++) lvl[i] = lvl_[i];
akt_wsk=0;
wynik = 0;
for (long long i=0; i<n; i++){
while (akt_wsk<i && lvl[i]>0){
long long 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 (long long i=0; i<n; i++){
if (lvl[i]>0){
long long 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--;
long long 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 |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Runtime error |
0 ms |
348 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
0 ms |
348 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
42 ms |
9720 KB |
Output is correct |
3 |
Correct |
45 ms |
9820 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
50 ms |
9748 KB |
Output is correct |
11 |
Incorrect |
50 ms |
9724 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Runtime error |
0 ms |
348 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Runtime error |
0 ms |
348 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |