Submission #334319

#TimeUsernameProblemLanguageResultExecution timeMemory
334319juggernautGift (IZhO18_nicegift)C++14
100 / 100
796 ms147700 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll n,k,sum,mx,i,a[1000001],mn,sz,res,cnt[1000001],j,tmp; vector<pair<ll,ll>>vec[1000001]; vector<ll>ans[1000001]; bool flag; int main(){ scanf("%lld%lld",&n,&k); for(i=1;i<=n;i++)scanf("%lld",&a[i]),mx=max(mx,a[i]),sum+=a[i]; if(sum%k!=0||mx>sum/k)return puts("-1"),0; tmp=0; for(i=1;i<=n;i++){ tmp+=a[i]; if(tmp>=sum/k){ vec[sz++].push_back({a[i]-tmp+sum/k,i}); tmp-=sum/k; if(tmp)vec[sz].push_back({tmp,i}); }else vec[sz].push_back({a[i],i}); } while(!flag){ mn=9e18; for(i=0;i<sz;i++)mn=min(mn,vec[i].back().first); cnt[res]=mn; flag=0; for(i=0;i<sz;i++){ ans[res].push_back(vec[i].back().second); if(vec[i].back().first==mn)vec[i].pop_back(); else vec[i].back().first-=mn; flag|=vec[i].empty(); } res++; } printf("%lld\n",res); for(i=0;i<res;i++){ printf("%lld",cnt[i]); for(j=0;j<k;j++)printf(" %lld",ans[i][j]); puts(""); } }

Compilation message (stderr)

nicegift.cpp: In function 'int main()':
nicegift.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 |     scanf("%lld%lld",&n,&k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
nicegift.cpp:10:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 |     for(i=1;i<=n;i++)scanf("%lld",&a[i]),mx=max(mx,a[i]),sum+=a[i];
      |                      ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...