제출 #1333318

#제출 시각아이디문제언어결과실행 시간메모리
1333318aaaaaaaaGym Badges (NOI22_gymbadges)C++20
100 / 100
190 ms12484 KiB
#include <bits/stdc++.h>
using namespace std;

#define all(x) x.begin(), x.end()
#define int long long

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);

    int n;
    cin >> n;

    vector<pair<int, int>> v(n);

    for(auto &it : v){
        cin >> it.first;
    }

    for(auto &it : v){
        cin >> it.second;
    }

    sort(all(v), [&](pair<int, int> p1, pair<int, int> p2){
        return p1.first + p1.second < p2.first + p2.second;
    });

    priority_queue<int> pq;

    int lv = 0;

    for(auto [X, L] : v){
        if(lv <= L){
            lv += X; pq.push(X);
        }else if(pq.top() > X){
            lv -= pq.top() - X;
            pq.push(X);
            pq.pop();
        }
    }

    cout << (int) pq.size() << "\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...