#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 998244353;
const ll LOGN = 20;
const ll MAXN = 5005;
vector<pair<pair<ll,ll>,int>> T;
vector<ll> empSuff;
int main() {
fast
int N;
cin >> N;
T = vector<pair<pair<ll,ll>,int>>(N);
ll sum = 0;
for (int i = 0; i < N; i++) {
cin >> T[i].f.s >> T[i].f.f;
sum += T[i].f.s;
T[i].s = i;
}
if (sum == 0) {
cout << N << "\n";
for (int i = 0; i < N; i++)
cout << 0 << " ";
return 0;
}
sort(T.begin(), T.end(), greater<pair<pair<ll,ll>,int>>());
for (int i = 0; i < N; i++) {
ll pour = min(sum, T[i].f.f);
T[i].f.s = pour;
sum -= pour;
}
vector<int> ans(N);
int cnt = 0;
for (int i = 0; i < N; i++) {
ans[T[i].s] = T[i].f.s;
if (ans[T[i].s] == 0)
cnt++;
}
cout << cnt << "\n";
for (auto u : ans)
cout << u << " ";
cout << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
600 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |