Submission #580988

#TimeUsernameProblemLanguageResultExecution timeMemory
580988AGEPod starim krovovima (COCI20_psk)C++14
50 / 50
2 ms340 KiB
#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)

psk.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   11 | main()
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...