Submission #1133487

#TimeUsernameProblemLanguageResultExecution timeMemory
1133487chinhhoangGym Badges (NOI22_gymbadges)C++20
100 / 100
132 ms10584 KiB
#include <bits/stdc++.h> using namespace std; const int N=5e5; struct gym{ int a,b,c; }A[N]; bool cmp(gym &a,gym &b){ return a.c<b.c; } int main(){ ios_base::sync_with_stdio(0); cin.tie(NULL);cout.tie(NULL); int n; cin>>n; for(int i=1;i<=n;i++)cin>>A[i].b; for(int i=1;i<=n;i++)cin>>A[i].a,A[i].c=A[i].a+A[i].b; sort(A+1,A+n+1,cmp); long long w=0,cnt=0; priority_queue<long long>pq; for(int i=1;i<=n;i++){ if(w<=A[i].a){ w+=A[i].b; cnt++; pq.push(A[i].b); }else if(pq.size()&&pq.top()>A[i].b){ w-=pq.top(); pq.pop(); pq.push(A[i].b); w+=A[i].b; } } cout<<cnt; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...