Submission #198716

#TimeUsernameProblemLanguageResultExecution timeMemory
198716sochoPod starim krovovima (COCI20_psk)C++14
50 / 50
7 ms504 KiB
#include "bits/stdc++.h" using namespace std; int main() { long long n; cin >> n; long long sm = 0; vector<pair<long long, long long> > gls; for (long long i=0; i<n; i++) { long long amount, cap; cin >> amount >> cap; gls.push_back(make_pair(cap, i)); sm += amount; } sort(gls.begin(), gls.end()); reverse(gls.begin(), gls.end()); long long take[n]; memset(take, 0, sizeof take); long long zr = 0; for (long long i=0; i<n; i++) { long long ca = gls[i].first, at = gls[i].second; long long ta = min(ca, sm); sm -= ta; take[at] = ta; if (ta == 0) zr++; } cout << zr << endl; for (long long i=0; i<n; i++) { cout << take[i] << ' '; } cout << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...