# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
543952 | AlperenT | Pod starim krovovima (COCI20_psk) | C++17 | 3 ms | 356 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 <bits/stdc++.h>
using namespace std;
const int N = 1000 + 5;
int n, ans[N];
struct Item{
int cur, total, i;
bool operator < (const Item &sc) const{
return array<int, 3>{total, cur, i} < array<int, 3>{sc.total, sc.cur, sc.i};
}
};
Item arr[N];
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
cin >> n;
for(int i = 1; i <= n; i++){
cin >> arr[i].cur >> arr[i].total;
arr[i].i = i;
}
sort(arr + 1, arr + n + 1);
for(int i = 1; i <= n; i++){
for(int j = i + 1; j <= n; j++){
int tmp = min(arr[i].cur, arr[j].total - arr[j].cur);
arr[i].cur -= tmp, arr[j].cur += tmp;
}
}
for(int i = 1; i <= n; i++) ans[arr[i].i] = arr[i].cur;
cout << count(ans + 1, ans + n + 1, 0) << "\n";
for(int i = 1; i <= n; i++) cout << ans[i] << " ";
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |