Submission #942338

#TimeUsernameProblemLanguageResultExecution timeMemory
942338vjudge1Gym Badges (NOI22_gymbadges)C++17
100 / 100
354 ms36856 KiB
#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int N; cin >> N; vector<tuple<int, int, int>> v(N, {0,0,0}); for(int i = 0; i < N; i++){ int X; cin >> X; get<0>(v[i]) += X; get<1>(v[i]) = X; } for(int i = 0; i < N; i++){ int L; cin >> L; get<0>(v[i]) += L; get<2>(v[i]) = L; } sort(v.begin(), v.end()); multiset<int> hv; int ans = 0; int lvl = 0; for(int i = 0; i < N; i++){ // cout << get<0>(v[i]) << " " << get<1>(v[i]) << " " << get<2>(v[i]) << "\n"; if(lvl <= get<2>(v[i])){ ans++; lvl += get<1>(v[i]); hv.insert(get<1>(v[i])); }else{ int mx = *hv.rbegin(); if(mx <= get<1>(v[i])) continue; hv.erase(hv.find(mx)); lvl -= mx; ans--; if(lvl <= get<2>(v[i])){ ans++; lvl += get<1>(v[i]); hv.insert(get<1>(v[i])); } } } cout << ans << "\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...