제출 #1185465

#제출 시각아이디문제언어결과실행 시간메모리
1185465SalihSahinGym Badges (NOI22_gymbadges)C++20
100 / 100
124 ms20436 KiB
#include "bits/stdc++.h" #define pb push_back #define int long long using namespace std; const int inf = 1e16; bool srt(pair<int, int> a, pair<int, int> b){ if(a.first + a.second != b.first + b.second) return (a.first + a.second < b.first + b.second); else return (a.first < b.first); } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin>>n; vector<int> x(n), l(n); vector<pair<int, int> > a(n); for(int i = 0; i < n; i++){ cin>>x[i]; } for(int i = 0; i < n; i++){ cin>>l[i]; a[i] = {x[i], l[i]}; } sort(a.begin(), a.end(), srt); int ans = 0, cur = 0; priority_queue<int> pq; for(int i = 0; i < n; i++){ if(cur <= a[i].second){ ans++; pq.push(a[i].first); cur += a[i].first; } else{ if(pq.top() > a[i].first){ cur -= pq.top(); pq.pop(); cur += a[i].first; pq.push(a[i].first); } } } cout<<ans<<endl; 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...