Submission #802862

#TimeUsernameProblemLanguageResultExecution timeMemory
802862Theo830Gym Badges (NOI22_gymbadges)C++17
100 / 100
496 ms46456 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define f(i,a,b) for(ll i = a;i < b;i++) #define pb push_back #define ii pair<ll,ll> #define F first #define S second int main(){ ll n; cin>>n; ll a[n],b[n]; f(i,0,n){ cin>>a[i]; } f(i,0,n){ cin>>b[i]; } vector<ii>arr; f(i,0,n){ arr.pb(ii(a[i]+b[i],a[i])); } sort(arr.begin(),arr.end()); ll sum = 0; multiset<ll>ex; f(i,0,n){ if(sum + arr[i].S <= arr[i].F){ sum += arr[i].S; ex.insert(arr[i].S); } else{ sum += arr[i].S; ex.insert(arr[i].S); auto it = ex.rbegin(); sum -= (*it); ex.erase(ex.find((*it))); } } cout<<ex.size()<<"\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...