# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
580988 | AGE | Pod starim krovovima (COCI20_psk) | C++14 | 2 ms | 340 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>
#define F first
#define S second
#define int long long
#define pb push_back
using namespace std;
const int N=1e6,M=2e3,mod=1e9+7;
pair<int,pair<int,int> > a[N];
int anss[N];
main()
{
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i].S.F>>a[i].F;
a[i].S.S=i;
}
sort(a,a+n);
int ans=0;
for(int i=1;i<=n;i++){
int emptyy=0;
for(int j=0;j<i;j++){
emptyy+=a[j].S.F;
}
int x=0;
for(int j=i;j<n;j++)
x+=a[j].F-a[j].S.F;
if(x>=emptyy)
ans=i;
}
int xx=0;
for(int i=0;i<ans;i++)
xx+=a[i].S.F;
for(int i=0;i<ans;i++){
anss[a[i].S.S]=0;
}
for(int i=ans;i<n;i++){
int xxx=min(a[i].F-a[i].S.F,xx);
xx-=xxx;
anss[a[i].S.S]=a[i].S.F+xxx;
}
int cnt=0;
for(int i=0;i<n;i++)
if(anss[i]==0)
cnt++;
cout<<cnt<<endl;
for(int i=0;i<n;i++)
cout<<anss[i]<<" ";
cout<<endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |