| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1316650 | lev | Gym Badges (NOI22_gymbadges) | C++20 | 117 ms | 12424 KiB |
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
using namespace std;
#ifdef LOCAL
#include "C:\Users\Dell\Downloads\template\template\icpc-notebook\Utilities\debug.h"
#else
#define debug(...) 42
#endif
const int mn = 5e5 + 5, mod = 1e9 + 7, inf = 2e9;
int n;
array <int, 2> a[mn];
bool cmp(array <int, 2> x, array<int, 2> y){
return x[0] + x[1] < y[0] + y[1];
}
void solve() {
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i][0];
for(int i = 1; i <= n; i++) cin >> a[i][1];
sort(a + 1, a + n + 1, cmp);
int cur = 0, ans = 0;
priority_queue <int> pq;
for(int i = 1; i <= n; i++){
debug(cur, a[i][0], a[i][1]);
if(pq.size()) debug(pq.top());
if(cur <= a[i][1]){
pq.push(a[i][0]);
cur += a[i][0], ans ++;
}
else if(i > 1 && a[i][0] < pq.top() && cur - pq.top() + a[i][0] <= a[i][1]){
cur -= pq.top(), cur += a[i][0];
pq.pop();
pq.push(a[i][0]);
}
}
cout << ans << '\n';
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
#define task "Kawabata"
if (fopen(task".INP", "r")) {
freopen(task".INP", "r", stdin);
freopen(task".OUT", "w", stdout);
}
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
}
// Don't wanna lose anymore T_T
// Never let me go - Kazuo Ishiguro
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
