Submission #872600

#TimeUsernameProblemLanguageResultExecution timeMemory
872600vjudge1Pod starim krovovima (COCI20_psk)C++17
50 / 50
1 ms4596 KiB
#include<bits/stdc++.h> #ifdef LOCAL #include "Essentials/algo/debug.h" #else #define debug(...) 69 #endif using namespace std; typedef long long ll; typedef pair<int,int> pii; const int N = 5e5 + 23; const ll inf = 1e18; #define F first #define S second #define pb push_back #define kill(x) cout<<x<<endl, exit(0); #define all(x) x.begin(),x.end() #define sz(x) (int)x.size() #define lc (v << 1) #define rc ((v<<1) |1) #define int ll int n; int a[N],b[N]; int sum= 0; int ans[N]; vector<int> ord; int32_t main() { cin.tie(nullptr)->sync_with_stdio(false); cin>>n; ord.resize(n); iota(all(ord), 0); for(int i = 0 ; i <n ; i++) { cin>>a[i] >> b[i]; sum += a[i]; } sort(all(ord) , [&] (int x,int y) { return b[x] > b[y];}); for(int i = 0 ; i< n ; i++) { ans[ord[i]] = min(sum, b[ord[i]]); sum -= min(sum,b[ord[i]]); } int cnt =0; for(int i = 0 ; i< n ; i++) if(ans[i] == 0) cnt ++; cout<<cnt << '\n'; for(int i = 0 ; i< n ; i++) cout<<ans[i] << ' '; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...