제출 #1174550

#제출 시각아이디문제언어결과실행 시간메모리
1174550weakweakweakGym Badges (NOI22_gymbadges)C++20
100 / 100
91 ms6492 KiB
#include <bits/stdc++.h> using namespace std; using pii = pair<int,int>; #define fs first #define sc second int n; pii a[510000]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i].sc; for (int i = 1; i <= n; i++) cin >> a[i].fs; sort(a+1, a+1+n, [](pii a, pii b){return a.fs+a.sc < b.fs+b.sc;}); priority_queue<int,vector<int>, less<int>> pq; int now = 0, ans = 0; for (int i = 1; i <= n; i++) { // cout << a[i].fs << ' ' << a[i].sc << ' ' << now << '\n'; if (now <= a[i].fs) { now += a[i].sc; ans++; pq.push(a[i].sc); } else if (pq.size() and now-pq.top()<=a[i].fs and pq.top()>a[i].sc) { now -= pq.top(); now += a[i].sc; pq.pop(); pq.push(a[i].sc); } } cout << ans << '\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...