#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
const int MOD = 998244353;
void solve(){
int n; cin >> n;
ll sum = 0;
vector<pair<int, int>> v(n);
for(int i = 0; i < n; i++){
int t, z; cin >> t >> z;
sum += t;
v[i] = {z, i};
}
vector<int> ans(n, 0);
sort(v.begin(), v.end());
int empty = n;
for(int i = n - 1; i >= 0 && sum > 0; i--){
ll am = min((ll)v[i].first, sum);
ans[v[i].second] = am;
sum -= am;
empty--;
}
cout << empty << endl;
for(int x : ans) cout << x << " ";
cout << endl;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("inpt.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
//int tt; cin >> tt;
int tt = 1;
for(int t = 1; t <= tt; t++){
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |