#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int total = 0;
vector<int> T(N), Z(N);
for (int i = 0;i < N; ++i) {
cin >> T[i] >> Z[i];
total += T[i];
}
vector<int> idx(N);
iota(idx.begin(), idx.end(), 0);
sort(idx.begin(), idx.end(), [&](int i, int j) { return Z[i] > Z[j]; });
vector<int> ans(N);
for (int i = 0;i < N; ++i) {
int j = idx[i];
ans[j] = min(total, Z[j]);
if (total < Z[j]) {
break;
}
total -= Z[j];
}
cout << count(ans.begin(), ans.end(), 0) << endl;
for (int i = 0;i < N; ++i) {
cout << ans[i] << ' ';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
344 KB |
Output isn't correct |