Submission #1147408

#TimeUsernameProblemLanguageResultExecution timeMemory
1147408PacybwoahGym Badges (NOI22_gymbadges)C++20
100 / 100
144 ms12484 KiB
#include<iostream> #include<vector> #include<queue> #include<algorithm> using namespace std; typedef long long ll; ll inf = 1e18; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<pair<ll, ll>> vec(n); for(int i = 0; i < n; i++) cin >> vec[i].second; for(int i = 0; i < n; i++) cin >> vec[i].first; for(int i = 0; i < n; i++) vec[i].first += vec[i].second; sort(vec.begin(), vec.end()); int ans = 0; ll now = 0; priority_queue<ll> pq; for(auto &[l, x]: vec){ if(now + x <= l){ ans++; now += x; pq.push(x); } else{ if(!pq.empty() && pq.top() > x){ now -= pq.top(); pq.pop(); now += x; pq.push(x); } } //cout << l << " " << x << "\n"; } cout << ans << "\n"; } // g++ -std=c++20 -Wall -Wextra -Wshadow -fsanitize=undefined -fsanitize=address -o run pB.cpp
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...