Submission #998303

#TimeUsernameProblemLanguageResultExecution timeMemory
998303cpptowinGym Badges (NOI22_gymbadges)C++17
9 / 100
145 ms18924 KiB
#include <bits/stdc++.h> #define fo(i, d, c) for (int i = d; i <= c; i++) #define fod(i, c, d) for (int i = c; i >= d; i--) #define maxn 1000010 #define N 1010 #define fi first #define se second #define pb emplace_back #define en cout << "\n"; #define int long long #define inf (int)1e18 #define pii pair<int, int> #define vii vector<pii> #define lb(x) x & -x #define bit(i, j) ((i >> j) & 1) #define offbit(i, j) (i ^ (1LL << j)) #define onbit(i, j) (i | (1LL << j)) #define vi vector<int> #define all(x) x.begin(),x.end() template <typename T1, typename T2> bool minimize(T1 &a, T2 b) { if (a > b) { a = b; return true; } return false; } template <typename T1, typename T2> bool maximize(T1 &a, T2 b) { if (a < b) { a = b; return true; } return false; } using namespace std; const int nsqrt = 450; const int mod = 1e9 + 7; int n; pii a[maxn]; main() { #define name "TASK" if (fopen(name ".inp", "r")) { freopen(name ".inp", "r", stdin); freopen(name ".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; fo(i,1,n) cin >> a[i].se; fo(i,1,n) cin >> a[i].fi; sort(a + 1,a + n + 1,[](pii a,pii b) { return a.fi < b.fi or (a.fi == b.fi and a.se < b.se); }); // fo(i,1,n) cout << a[i].fi << ' ' << a[i].se << "\n"; priority_queue<int> q; int sum = 0; int ans = 0; int now = 0; int tot = 0; fo(i,1,n) { vi v; while(q.size() and sum > a[i].fi) { sum -= q.top(); v.pb(q.top()); q.pop(); now--; } now++; q.push(a[i].se); sum += a[i].se; if(ans < now or (ans == now and tot < sum)) { ans = now; tot = sum; } else { for(int it : v) sum += it,q.push(it); sum -= a[i].se; } } cout << ans; }

Compilation message (stderr)

Main.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   45 | main()
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         freopen(name ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen(name ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...