제출 #1319282

#제출 시각아이디문제언어결과실행 시간메모리
1319282chithanhnguyenGym Badges (NOI22_gymbadges)C++20
100 / 100
120 ms12464 KiB
/* Author: Nguyen Chi Thanh - High School for the Gifted - VNU.HCM (i2528) */ #include <bits/stdc++.h> using namespace std; #define int long long #define ull unsigned long long #define ld long double #define pii pair<int, int> #define fi first #define se second #define __builtin_popcount __builtin_popcountll #define all(x) (x).begin(), (x).end() #define BIT(x, i) (((x) >> (i)) & 1) #define MASK(x) ((1ll << (x))) #define debug(a, l, r) for (int _i = (l); _i <= (r); ++_i) cout << (a)[_i] << ' '; cout << '\n'; struct Gym { int cap, gain; bool operator < (const Gym &other) const { return cap + gain < other.cap + other.gain; } }; const int MAXN = 5e5 + 5; int n; Gym a[MAXN]; void init() { cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i].gain; for (int i = 1; i <= n; ++i) cin >> a[i].cap; sort(a + 1, a + n + 1); } void solve() { priority_queue<int> pq; int exp = 0, gyms = 0;; for (int i = 1; i <= n; ++i) { if (exp <= a[i].cap) { exp += a[i].gain; pq.push(a[i].gain); ++gyms; } else if (!pq.empty() && a[i].gain < pq.top()) { exp -= pq.top(); pq.pop(); exp += a[i].gain; pq.push(a[i].gain); } } cout << gyms; } signed main() { #ifdef NCTHANH freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); init(); solve(); 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...