Submission #198964

#TimeUsernameProblemLanguageResultExecution timeMemory
198964virchau13Pod starim krovovima (COCI20_psk)C++17
50 / 50
7 ms376 KiB
#include <iostream> #include <algorithm> #include <set> #include <deque> using namespace std; long long arr[1007]; int main(){ int n, a; cin >> n; long long idx[n], ans[n]; long long t = 0; for(int i = 0; i < n; i++){ cin >> a >> arr[i]; t += a; idx[i] = i; ans[i] = 0; } sort(idx, idx+n, [](long long i, long long j){ return arr[i] > arr[j]; }); int i = 0; for(; i < n; i++){ t -= arr[idx[i]]; ans[idx[i]] = (t < 0 ? arr[idx[i]] + t : arr[idx[i]]); if(t <= 0) break; } cout << (n-i-1) << '\n'; for(int i = 0; i < n; i++){ cout << ans[i] << ' '; } cout << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...