Submission #886677

#TimeUsernameProblemLanguageResultExecution timeMemory
886677vjudge1Gym Badges (NOI22_gymbadges)C++17
100 / 100
351 ms33944 KiB
#include <bits/stdc++.h> #define pb push_back #define all(aa) aa.begin(), aa.end() using namespace std; typedef long long ll; int main(){ int n; cin >> n; vector<ll> L(n), X(n); for(int i = 0; i < n; i++) cin >> X[i]; for(int i = 0; i < n; i++) cin >> L[i]; vector<array<ll, 3>> G(n); for(int i = 0; i < n; i++){ G[i] = {L[i] + X[i], L[i], X[i]}; } sort(all(G)); priority_queue<ll> vals; ll score = 0, ans = 0; for(int i = 0; i < n; i++){ auto [a, Li, Xi] = G[i]; if(score <= Li){ vals.push(Xi); score += Xi; ans++; } else if(vals.top() > Xi){ score -= vals.top(); vals.pop(); score += Xi; vals.push(Xi); } } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...