#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+37;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n; cin >> n;
vector<int> a(n), ind(n), ans(n);
iota(ind.begin(), ind.end(), 0);
int sum=0;
for (int i=0; i<n; i++){
int x; cin >> x; sum+=x;
cin >> a[i];
}
sort(ind.begin(), ind.end(), [&](int i, int j){
return a[i] > a[j];
});
int s=0;
for(int i=0; i<n; i++){
int v=min(sum, a[ind[i]]);
if(v==0) s++;
ans[ind[i]]=v;
sum-=v;
}
cout<<s<<"\n";
for(auto i: ans) cout<<i<<" ";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |