Submission #1326753

#TimeUsernameProblemLanguageResultExecution timeMemory
1326753hieptkGym Badges (NOI22_gymbadges)C++20
100 / 100
123 ms12468 KiB
#include <iostream>
#include <vector>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <cstring>
#include <unordered_map>
#include <iomanip>
#include <queue>
#include <map>
#include <sstream>
#include <stack>
#include <bitset>
#include <random>

using ll = long long;

using namespace std;

constexpr int nm = 500002;

int n;
pair<ll, ll> a[nm];

bool cmp(pair<ll, ll> &a, pair<ll, ll> &b) {
    return a.first + a.second < b.first + b.second;
}

int main() {
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i].second;
    for (int i = 1; i <= n; ++i) cin >> a[i].first;
    sort(a + 1, a + n + 1, cmp);

    // memset(dp, 0x3f, sizeof(dp));
    // dp[0][0] = 0;
    // for (int i = 1; i <= n; ++i) {
    //     dp[i][0] = 0;
    //     for (int j = 1; j <= i; ++j) {
    //         dp[i][j] = dp[i - 1][j];
    //         if (dp[i - 1][j - 1] <= a[i].first) {
    //             dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + a[i].second);
    //         }
    //     }
    // }

    // for (int i = n; i >= 0; --i) {
    //     if (dp[n][i] < 1e18) {
    //         cout << i << "\n";
    //         return 0;
    //     }
    // }

    ll h = 0;
    priority_queue<ll> q;
    for (int i = 1; i <= n; ++i) {
        // cout << a[i].first << " " << a[i].second << "\n";
        if (h <= a[i].first) {
            q.push(a[i].second);
            h += a[i].second;
        } else if (a[i].second < q.top()) {
            h -= q.top();
            q.pop();
            q.push(a[i].second);
            h += a[i].second;
        }
    }
    cout << q.size() << "\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...