Submission #844222

#TimeUsernameProblemLanguageResultExecution timeMemory
844222vjudge1Pod starim krovovima (COCI20_psk)C++17
40 / 50
2 ms492 KiB
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int total = 0; vector<int> T(N), Z(N); for (int i = 0;i < N; ++i) { cin >> T[i] >> Z[i]; total += T[i]; } vector<int> idx(N); iota(idx.begin(), idx.end(), 0); sort(idx.begin(), idx.end(), [&](int i, int j) { return Z[i] > Z[j]; }); vector<int> ans(N); for (int i = 0;i < N; ++i) { int j = idx[i]; ans[j] = min(total, Z[j]); if (total < Z[j]) { break; } total -= Z[j]; } cout << count(ans.begin(), ans.end(), 0) << endl; for (int i = 0;i < N; ++i) { cout << ans[i] << ' '; } }
#Verdict Execution timeMemoryGrader output
Fetching results...