Submission #1222223

#TimeUsernameProblemLanguageResultExecution timeMemory
1222223overwatch9Bikeparking (EGOI24_bikeparking)C++20
25 / 100
25 ms4936 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector <ll> X(n), Y(n);
    for (int i = 0; i < n; i++)
        cin >> X[i];
    for (int i = 0; i < n; i++)
        cin >> Y[i];

    ll ans = 0;
    int p1 = n-2;
    for (int i = n-1; i >= 0 && p1 >= 0; i--) {
        while (p1 >= 0 && (X[p1] == 0 || p1 >= i)) {
            p1--;
        }
        while (p1 >= 0 && Y[i] > 0) {
            if (X[p1] == 0) {
                p1--;
                continue;
            }
            int amt = min(X[p1], Y[i]);
            Y[i] -= amt;
            X[p1] -= amt;
            ans += amt;
        }
    }
    for (int i = n-1; i >= 0; i--) {
        if (Y[i] > 0 && X[i] > 0) {
            int amt = min(Y[i], X[i]);
            Y[i] -= amt;
            X[i] -= amt;
        }
    }

    p1 = n-1;
    for (int i = 0; i < n; i++) {
        while (p1 >= 0 && (X[p1] == 0)) {
            p1--;
        }
        while (p1 >= 0 && Y[i] > 0) {
            if (X[p1] == 0) {
                p1--;
                continue;
            }
            int amt = min(X[p1], Y[i]);
            Y[i] -= amt;
            X[p1] -= amt;
            ans -= amt;
        }
    }

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