제출 #1341243

#제출 시각아이디문제언어결과실행 시간메모리
1341243sallyBikeparking (EGOI24_bikeparking)C++20
25 / 100
103 ms5104 KiB
#include <iostream>
#include <vector>
using namespace std;
#define int long long

signed main() {
    int N;
    cin >> N;
    vector<int> slot(N), person(N);
    for (int i = 0; i < N; i++) cin >> slot[i];
    for (int i = 0; i < N; i++) cin >> person[i];

    int ptr = 0, ans = 0;
    for (int i = 0; i < N; i++) {
        int need = person[i];
        for (int t = ptr; t < i && need; t++) {
            int take = min(need, slot[t]);
            slot[t] -= take;
            need -= take;
            ans += take; // upvotes
        }
        while (ptr < N && slot[ptr] == 0) ptr++; // 修正順序
        person[i] = need;
    }

    // 分配同 tier
    for (int i = 0; i < N; i++) {
        int take = min(slot[i], person[i]);
        slot[i] -= take;
        person[i] -= take;
        // 同 tier → 不加不扣
    }

    // 剩下的人只能往更高 tier → downvotes
    for (int i = 0; i < N; i++) {
        ans -= person[i];
    }

    cout << ans;
}
#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...