Submission #899192

#TimeUsernameProblemLanguageResultExecution timeMemory
899192BlagojPod starim krovovima (COCI20_psk)C++17
40 / 50
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define ll long long #define all(x) (x).begin(), (x).end() int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<pair<ll, ll>> a(n); ll sum = 0; for (int i = 0; i < n; i++) { ll x; cin >> x >> a[i].first; a[i].second = i; sum += x; } sort(all(a)); reverse(all(a)); ll left = n; ll ans[n]; memset(ans, 0, sizeof(ans)); for (int i = 0; i < n; i++) { left--; ans[a[i].second] = max(a[i].first, sum - a[i].first); sum -= a[i].first; if (sum <= 0) break; } cout << left << endl; for (int i = 0; i < n; i++) cout << ans[i] << " "; }
#Verdict Execution timeMemoryGrader output
Fetching results...