Submission #1343258

#TimeUsernameProblemLanguageResultExecution timeMemory
1343258coin_Bikeparking (EGOI24_bikeparking)C++20
68 / 100
1095 ms5132 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    // ignore the 0 people
    // go from 1 to n-1, if there exist space for them of at least 1 tier higher (smallest possible), put them there, else ignore
    // go from 0 to n-1, since they were ignored, try to fit them in their own tier
    // if impossible, then put them in the lowest tier possible (can ignore and then just -1)
    for (int i = 0; i < n; i++){
        cin >> x[i];
    }
    for (int i = 0; i < n; i++){
        cin >> y[i];
    }
    int ans = 0;
    for (int i = 1; i < n; i++){
        // put at next availible slot
        for (int j = i-1; j >= 0 && y[i] > 0; j--){
            int fit = min(x[j], y[i]);
            ans += fit;
            x[j] -= fit;
            y[i] -= fit;
        }
    }
    for (int i = 0; i < n; i++){
        int fit = min(x[i], y[i]);
        x[i] -= fit;
        y[i] -= fit;
        ans -= y[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...