Submission #1214313

#TimeUsernameProblemLanguageResultExecution timeMemory
1214313fadak-14Bikeparking (EGOI24_bikeparking)C++20
100 / 100
30 ms7496 KiB
#include <bits/stdc++.h>
#define ll long long
#define db double
#define ld long double
#define endl '\n'
#define eb emplace_back 
#define em emplace
#define pb push_back
#define pf push_front
#define pp pop_back
#define fr first
#define sc second
#define sz size
#define ir insert
using namespace std;
const ll md =1e9 + 7;
const ll mx = 1e9 ;
signed main() { 
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie() ;
    ll n ;cin >>  n;
    vector<ll> a(n) , b(n) ;
    for(ll i =0  ; i < n ; i++) cin>> a[i] ;
    for(ll i =0  ;i < n ; i++)cin >>b[i] ;
    stack<ll> s ;
    ll r1 = 0 , r2 = 0 ;
    for(ll i =0  ; i < n ; i++) {
        if(i && a[i -1]) s.push(i - 1) ;
        while(s.sz() && b[i]){
            ll j = s.top() ; ll tk = min(b[i] , a[j]) ;
            b[i] -= tk ; a[j] -= tk ;
            r1+= tk;
            if(a[j] == 0) s.pop() ;
        }
    }
    for(ll i = 0;  i <  n ; i++) {
        ll tk=min(a[i] ,b[i] );
        a[i] -= tk ; b[i] -=tk ;
        r2 += b[i] ;
    }
    cout <<r1- r2 << endl ;
    return 0;
} 

    
#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...