Submission #1092746

#TimeUsernameProblemLanguageResultExecution timeMemory
1092746Hacv16Pod starim krovovima (COCI20_psk)C++17
50 / 50
1 ms360 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int const int MAX = 2e5 + 10; int n, t[MAX], z[MAX]; int ans[MAX]; int32_t main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for(int i = 1; i <= n; i++) cin >> t[i] >> z[i]; vector<int> glasses(n); iota(glasses.begin(), glasses.end(), 1); sort(glasses.begin(), glasses.end(), [&](int i, int j){ return z[i] > z[j]; }); int totalDrink = accumulate(t + 1, t + 1 + n, 0LL); int respZero = 0; for(auto glassId : glasses) { ans[glassId] = min(z[glassId], totalDrink); totalDrink -= min(z[glassId], totalDrink); if(!ans[glassId]) respZero++; } cout << respZero << '\n'; for(int i = 1; i <= n; i++) cout << ans[i] << ' '; cout << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...