제출 #1337679

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

#define fi first
#define se second

typedef pair<int,int> pii;

const int MaxN = 1e6+7;

int n;
pii a[MaxN];

bool cmp(pii a,pii b) {
    return a.fi + a.se < b.fi + b.se;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i=1;i<=n;i++) cin >> a[i].fi;
    for (int i=1;i<=n;i++) cin >> a[i].se;
    sort(a+1,a+n+1,cmp);
    int strong = 0;
    priority_queue<int> pq;
    for (int i=1;i<=n;i++) {
        strong += a[i].fi;
        pq.push(a[i].fi);
        if (strong > a[i].se + a[i].fi) {
            strong -= 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...