# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1062757 | MasterMoon | Pod starim krovovima (COCI20_psk) | C++17 | 1 ms | 348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|---|---|---|---|
Fetching results... |