Submission #1314826

#TimeUsernameProblemLanguageResultExecution timeMemory
1314826samarthkulkarniGym Badges (NOI22_gymbadges)C++20
0 / 100
72 ms10424 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define vi vector<long long> #define all(x) x.begin(), x.end() #define endl "\n" #define pr pair<ll, ll> #define ff first #define ss second void solution(); int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); solution(); return 0; } const int N = 5e5+10; pr a[N]; void solution() { ll n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i].ff; for (int i = 0; i < n; i++) cin >> a[i].ss; priority_queue<ll> q; ll ans = 0; ll x = 0; for (int i = 0; i < n; i++) { if (a[i].ss >= x) { x += a[i].ff; ans++; q.push(a[i].ff); } else { if (q.size() > 0 && a[i].ss >= x-q.top() && a[i].ff <= q.top()) { x -= q.top(); x += a[i].ff; } } } 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...