Submission #1357130

#TimeUsernameProblemLanguageResultExecution timeMemory
1357130hsuan._.0528Bikeparking (EGOI24_bikeparking)C++20
25 / 100
18 ms5112 KiB

//pB
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int maxn = 3e5+10;

int n;
LL ans=0;
LL x[maxn], y[maxn];


signed main(){
    ios_base::sync_with_stdio(0);  cin.tie(0);

    cin>>n;

    for(int i=0; i<n; i++)  cin>>y[i]; // 房間
    for(int i=0; i<n; i++)  cin>>x[i]; // 人

    int yy=n-1, xx=n-1;
    for(; yy>=0 and xx>=0; xx--){
        if(xx==yy)  yy--;
        while(x[xx] and yy>=0){
            LL mi = min(y[yy], x[xx]);
            ans += mi;
            x[xx] -= mi;
            y[yy] -= mi;
            if(y[yy] == 0)  yy--;
        }
        if(x[xx])  break;
    }
   // cout<<xx<<" "<<yy<<"\n";
    while(xx>=0){
       // cout<<x[xx]<<" "<<y[xx]<<"\n";
        if(y[xx]){
            LL mi = min(y[xx], x[xx]);
            x[xx] -= mi;
            y[yy] -= mi;
        }
        ans -= x[xx];
        xx--;
    }

    cout<<ans;
    return 0;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...