#include <iostream>
#include <algorithm>
using namespace std;
#define int long long
int rasp[1001];
struct pahar{
int a,ind;
} v[1001];
bool cmp(pahar a,pahar b){
return a.a>b.a;
}
signed main()
{
int i,a,n,sum=0,cnt=0;
cin>>n;
for(i=1;i<=n;i++){
cin>>a>>v[i].a;
v[i].ind=i;sum+=a;
}
sort(v+1,v+n+1,cmp);
for(i=1;i<=n;i++){
if(sum){
rasp[v[i].ind]=min(sum,v[i].a);
sum-=min(sum,v[i].a);
}else cnt++;
}
cout<<cnt<<"\n";
for(i=1;i<=n;i++) cout<<rasp[i]<<" ";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |