Submission #1295305

#TimeUsernameProblemLanguageResultExecution timeMemory
1295305chaitanyamehtaGym Badges (NOI22_gymbadges)C++20
100 / 100
386 ms31740 KiB
// https://oj.uz/problem/view/NOI22_gymbadges
#include<bits/stdc++.h>
using namespace std;

#define int long long

signed main(){
    int n;
    cin>>n;
    vector<pair<int , int>> a(n);
    vector<int> x(n), l(n);
    for(int i = 0 ; i < n; i++) cin>>x[i];
    for(int i = 0; i < n  ; i++)cin>>l[i];

    vector<pair<int , int>> gyms;
    for(int i = 0 ; i < n ;i++){
        int d = x[i] + l[i];
        gyms.push_back({d , x[i]});
    }
    sort(gyms.begin() , gyms.end());

    int total = 0;
    priority_queue<int> pq;
    for(auto &g : gyms){
        int d = g.first;
        int x = g.second;
        total += x;
        pq.push(x);
        if(total > d){
            total -= pq.top();
            pq.pop();
        }
    }
    cout << pq.size();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...