Submission #991918

#TimeUsernameProblemLanguageResultExecution timeMemory
991918toast12Gym Badges (NOI22_gymbadges)C++14
9 / 100
262 ms14020 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long

int main() {
    int n;
    cin >> n;
    vector<pair<ll, ll>> gyms(n);
    for (int i = 0; i < n; i++) {
        cin >> gyms[i].second;
    }
    for (int i = 0; i < n; i++) {
        cin >> gyms[i].first;
    }
    sort(gyms.begin(), gyms.end());
    ll level = 0;
    ll ans = 0;
    priority_queue<ll> pq;
    for (int i = 0; i < n; i++) {
        if (level <= gyms[i].first) {
            level += gyms[i].second;
            pq.push(gyms[i].second);
            ans++;
        }
        else {
            ll x = pq.top();
            if (level-x <= gyms[i].first && x >= gyms[i].second) {
                pq.pop();
                pq.push(gyms[i].second);
                level -= x;
                level += gyms[i].second;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...