Submission #868760

#TimeUsernameProblemLanguageResultExecution timeMemory
868760PringPod starim krovovima (COCI20_psk)C++14
50 / 50
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define fs first #define sc second #define mp make_pair typedef pair<int, int> pii; typedef pair<pii, int> p3i; const int MXN = 1005; int n, sum; p3i p[MXN]; void miku() { cin >> n; for (int i = 0; i < n; i++) { cin >> p[i].fs.sc >> p[i].fs.fs; sum += p[i].fs.sc; p[i].fs.sc = 0; p[i].sc = i; } sort(p, p + n, greater<p3i>()); for (int i = 0; i < n; i++) { if (sum >= p[i].fs.fs) { p[i].fs.sc = p[i].fs.fs; sum -= p[i].fs.fs; } else { p[i].fs.sc = sum; break; } } sort(p, p + n, [](p3i a, p3i b) -> bool { return a.sc < b.sc; }); int ans = 0; for (int i = 0; i < n; i++) if (p[i].fs.sc == 0) ans++; cout << ans << endl; for (int i = 0; i < n; i++) cout << p[i].fs.sc << ' '; cout << endl; } int32_t main() { cin.tie(0) -> sync_with_stdio(false); miku(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...