#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define __Master_Moon__ int main()
struct hung
{
ll x,y;
};
bool cmp(hung a,hung b)
{
return a.y > b.y;
}
void solve()
{
int n,ans = 0;
cin >> n;
hung a[n];
for(int i = 0;i < n;i++) cin >> a[i].x >> a[i].y;
sort(a,a+n,cmp);
for(int i = 0;i< n;i++)
{
for(int j = i + 1;j < n;j++)
{
if(a[i].x == a[i].y) break;
if(a[i].x + a[j].x <= a[i].y)
{
a[i].x+=a[j].x;
a[j].x = 0;
}
else
{
a[j].x-= (a[i].y-a[i].x);
a[i].x=a[i].y;
break;
}
}
if(a[i].x == 0) ans++;
}
cout << ans << endl;
for(int i = 0;i < n;i++) cout << a[i].x << " ";
}
__Master_Moon__
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("o.inp","r",stdin);
//freopen("o.out","w",stdout);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
348 KB |
Output is correct |
5 |
Partially correct |
1 ms |
348 KB |
Output is partially correct |
6 |
Partially correct |
0 ms |
348 KB |
Output is partially correct |
7 |
Partially correct |
0 ms |
348 KB |
Output is partially correct |
8 |
Partially correct |
1 ms |
348 KB |
Output is partially correct |
9 |
Partially correct |
1 ms |
348 KB |
Output is partially correct |
10 |
Partially correct |
1 ms |
348 KB |
Output is partially correct |