#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 |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
352 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |