#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
const ll mxn = 1010;
pll arr[mxn];
ll ans[mxn];
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n;
cin>>n;
ll sum = 0;
priority_queue<pll,vector<pll>,less<pll>> pq;
for(int i =1;i<=n;i++){
cin>>arr[i].fs>>arr[i].sc;
pq.push({arr[i].sc,i});
sum += arr[i].fs;
}
while(sum>pq.top().fs){
ans[pq.top().sc] = pq.top().fs;
sum -= pq.top().fs;
pq.pop();
}
ans[pq.top().sc] = sum;
ll cnt = 0;
for(int i = 1;i<=n;i++)if(!ans[i])cnt++;
cout<<cnt<<'\n';
for(int i = 1;i<=n;i++)cout<<ans[i]<<' ';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
464 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |