Submission #379233

#TimeUsernameProblemLanguageResultExecution timeMemory
379233jass921026Gift (IZhO18_nicegift)C++14
100 / 100
748 ms124536 KiB
#include<bits/stdc++.h> using namespace std; #define jizz ios_base::sync_with_stdio(false);cin.tie(NULL); typedef long long ll; typedef pair<ll,int> pii; #define F first #define S second #define ALL(x) (x).begin(),(x).end() #define pb push_back #define mkp make_pair const int MAXN=1E6+10, MAX_OPS=3E6; ll A[MAXN]; vector<ll> val; vector<vector<int> > idx; vector<int> now; vector<pii> tmp; int main(){ jizz int n, k; cin>>n>>k; ll sum=0, mxa=0; for(int i=1;i<=n;i++){ cin>>A[i]; sum+=A[i]; mxa=max(mxa,A[i]); } if(sum%k>0){ cout<<"-1\n"; return 0; } if(mxa>sum/k){ cout<<"-1\n"; return 0; } ll cur=0; for(int i=1;i<=n;i++){ if(cur==0) now.pb(i); cur=cur+A[i]; if(cur>sum/k){ now.pb(i); cur-=sum/k; } tmp.pb(mkp(cur,now.size()-1)); } sort(ALL(tmp)); ll last=0; for(int i=0;i<n;i++){ //cout<<"hi "<<tmp[i].F<<" "<<tmp[i].S<<"\n"; if(tmp[i].F!=last){ val.pb(tmp[i].F-last); idx.pb(now); } now[tmp[i].S]++; last=tmp[i].F; } cout<<val.size()<<"\n"; for(int i=0;i<val.size();i++){ cout<<val[i]<<" "; for(int j=0;j<k;j++){ cout<<idx[i][j]<<" \n"[j==k-1]; } } return 0; }

Compilation message (stderr)

nicegift.cpp: In function 'int main()':
nicegift.cpp:56:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     for(int i=0;i<val.size();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...