제출 #1222304

#제출 시각아이디문제언어결과실행 시간메모리
1222304overwatch9Bikeparking (EGOI24_bikeparking)C++20
9 / 100
163 ms20296 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int n;
    cin >> n;
    set <pair <ll, int>> X;
    for (int i = 0; i < n; i++) {
        int tp;
        cin >> tp;
        if (tp > 0)
            X.insert({i, tp});
    }
    vector <int> Y(n);
    for (int i = 0; i < n; i++)
        cin >> Y[i];

    ll ans = 0;

    for (int i = 0; i < n; i++) {
        if (Y[i] == 0)
            continue;
        while (Y[i] > 0) {
            auto it = X.lower_bound({i, 0});
            if (it == X.begin())
                break;
            it--;
            if (it->first >= i)
                break;
            int x = it->second;
            int id = it->first;
            X.erase(it);
            int amt = min(x, Y[i]);
            Y[i] -= amt;
            x -= amt;
            ans += amt;
            if (x > 0)
                X.insert({id, x});
        }

    }

    for (int i = 0; i < n; i++) {
        if (Y[i] == 0)
            continue;
        auto it = X.lower_bound({i, 0});
        if (it != X.end()) {
            it--;
            if (it->first != i) {
                ans -= Y[i];
                continue;
            }
            int x = it->second;
            int id = it->first;
            X.erase(it);
            int amt = min(Y[i], x);
            Y[i] -= amt;
            x -= amt;
            if (Y[i] > 0)
                ans -= Y[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...