Submission #899193

#TimeUsernameProblemLanguageResultExecution timeMemory
899193BlagojPod starim krovovima (COCI20_psk)C++17
50 / 50
1 ms468 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] = min(a[i].first, sum); 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...