제출 #1353064

#제출 시각아이디문제언어결과실행 시간메모리
1353064Francisco_MartinBikeparking (EGOI24_bikeparking)C++20
100 / 100
73 ms7408 KiB
//EGOI 2024 Bike Parking
//https://qoj.ac/contest/1765/problem/9187

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;

int main(){
    ll n, ans=0; 
    cin >> n;
    vll A(n), B(n); stack<ll> stk;
    for(int i=0; i<n; i++) cin >> A[i];
    for(int i=0; i<n; i++) cin >> B[i];
    for(int i=0; i<n; i++){
        while(B[i]>0 && !stk.empty()){
            ll id=stk.top(), x=min(A[id],B[i]); stk.pop();
            A[id]-=x; B[i]-=x; ans+=x;
            if(A[id]!=0) stk.push(id);
        }
        if(A[i]!=0) stk.push(i);
    }
    for(int i=0; i<n; i++){
        ll x=min(A[i],B[i]);
        A[i]-=x, B[i]-=x;
    }
    for(int i=0; i<n; i++) ans-=B[i];
    cout << ans << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...