Submission #1284530

#TimeUsernameProblemLanguageResultExecution timeMemory
1284530cheskaGym Badges (NOI22_gymbadges)C++20
100 / 100
151 ms14700 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll, ll>
#define ppii pair<ll, pii> 
#define tiii tuple<ll, ll, ll>
#define g0 get<0>
#define g1 get<1>
#define g2 get<2>
#define f first
#define s second
#define pb push_back
const ll N = 2e5+5;
const ll MOD = 1e9+7;
vector<int> x, l;
bool comp(int i, int j) {
    return (x[i]+l[i] < x[j]+l[j]);
}
signed main() {
   // freopen("in.in", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    x.resize(n); l.resize(n);
    for (int i = 0; i < n; i++) cin >> x[i];
    for (int i = 0; i < n; i++) cin >> l[i];
    vector<int> o(n);
    for (int i = 0; i < n; i++) o[i] = i;
    sort(o.begin(), o.end(), comp);
    priority_queue<pii> q;
    int s = 0;
    for (int i : o) {
        if (l[i] >= s) {
            q.push({x[i], i});
            s += x[i];
        }
        else if ((q.top()).f > x[i]) {
            s -= (q.top()).f;
            q.pop();
            q.push({x[i], i});
            s += x[i];
        }
    }
    cout << q.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...