Submission #1017189

#TimeUsernameProblemLanguageResultExecution timeMemory
1017189vjudge1Pod starim krovovima (COCI20_psk)C++17
50 / 50
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { int n; cin>>n; int x,y,su=0; vector<pair<int,int>> cap; for (int i=0;i<n;i++) { cin>>x>>y; su+=x; cap.push_back({y,i}); } sort(rbegin(cap),rend(cap)); int ans=0,a[n]={}; if (!su) ans=n; else { for (int i=0;i<n;i++) { a[cap[i].second]=min(cap[i].first,su); su-=a[cap[i].second]; if (!su) { ans=n-i-1; break; } } } cout<<ans<<endl; for (int i=0;i<n;i++) cout<<a[i]<<' '; cout<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...