# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
844224 | vjudge1 | Pod starim krovovima (COCI20_psk) | C++17 | 1 ms | 352 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;
#ifdef DEBUG
#include "/Users/kutay/CP/templates/debug.h"
#else
#define debug(...) void(38)
#endif
#define int long long
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n; cin >> n;
vector<pair<int, pair<int, int>>> a(n);
int l = 0, s = 0;
for (int i = 0; i < n; i++) {
cin >> a[i].second.first >> a[i].second.second;
l += a[i].second.first;
s += a[i].second.second;
a[i].first = i;
}
sort(a.begin(), a.end(), [](pair<int, pair<int, int>> x, pair<int, pair<int, int>> y) {
return x.second.second < y.second.second;
});
int k = s - l, cnt = 0;
for (int i = 0; i < n; i++) {
if (a[i].second.second <= k) {
a[i].second.first = 0;
k -= a[i].second.second;
cnt++;
} else {
a[i].second.first = a[i].second.second - k;
k = 0;
}
}
sort(a.begin(), a.end());
cout << cnt << '\n';
for (int i = 0; i < n; i++) cout << a[i].second.first << " ";
cout << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |