제출 #1166778

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

using namespace std;
 
 
#define all(x) x.begin(), x.end()
#define mod 1000000007
#define sp << " " <<
#define endl << '\n'


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int N;
    cin >> N;
    int ret = 0;
    vector<int> slots(N);
    vector<int> customers(N);
    for (int i = 0; i < N; i++){
        cin >> slots[i];
    }
    for (int i = 0; i < N; i++){
        cin >> customers[i];
    }
    int o = N - 2;
    for (int i = N - 1; i >= 0; i--){
        o = min(o, i - 1);
        while (customers[i] && o >= 0){
            if (slots[o] >= customers[i]){
                ret += customers[i];
                slots[o] -= customers[i];
                customers[i] = 0;
            }else{
                ret += slots[o];
                customers[i] -= slots[o];
                slots[o] = 0;
                o--;
            }
        }
        if (o < 0 && customers[i]){
            ret -= max(0, customers[i] - slots[i]);
            slots[i] = max(0, slots[i] - customers[i]);
            customers[i] = 0;
        }
    }
    cout << ret;
}
#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...