#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
int n;
cin>>n;
int x,y,su=0;
vector<pair<int,int>> cap;
for (int i=0;i<n;i++)
{
cin>>x>>y;
su+=x;
cap.push_back({y,i});
}
sort(rbegin(cap),rend(cap));
int ans=0,a[n]={};
if (!su)
ans=n;
else
{
for (int i=0;i<n;i++)
{
a[cap[i].second]=min(cap[i].first,su);
su-=a[cap[i].second];
if (!su)
{
ans=n-i-1;
break;
}
}
}
cout<<ans<<endl;
for (int i=0;i<n;i++)
cout<<a[i]<<' ';
cout<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 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 |
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 |