# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
198964 | virchau13 | Pod starim krovovima (COCI20_psk) | C++17 | 7 ms | 376 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |