제출 #1306049

#제출 시각아이디문제언어결과실행 시간메모리
1306049syanvuBikeparking (EGOI24_bikeparking)C++20
25 / 100
32 ms5132 KiB
#include <bits/stdc++.h>

#define pb push_back
#define SS ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#define int long long
#define all(v) v.begin(),v.end()
using namespace std;

const int N = 1e4, inf = 1e9 + 1, mod = 998244353;

void solve(){
    int n;
    cin >> n;
    int x[n + 1], y[n + 1];
    for(int i = 1; i <= n; i++){
        cin >> x[i];
    }    
    for(int i = 1; i <= n; i++){
        cin >> y[i];
    }
    reverse(x + 1, x + n + 1);
    reverse(y + 1, y + n + 1);
    int j = 1;
    int ans = 0;
    for(int i = 1; i <= n; i++){
        while(j <= i) j++;
        while(j <= n && y[i] > 0){
            if(y[i] >= x[j]){
                y[i] -= x[j];
                ans += x[j];
                x[j] = 0;
            }
            else{
                x[j] -= y[i];
                ans += y[i];
                y[i] = 0;
            }
            j++;
        }
        if(y[i] > 0){
            y[i] -= x[i];
            y[i] = max(0ll, y[i]);
            ans -= y[i];
        }
    }
    cout << ans;
}
signed main(){ 
    SS
    // freopen("trains.in", "r", stdin);
    // freopen("trains.out", "w", stdout);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}
#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...