Submission #84910

#TimeUsernameProblemLanguageResultExecution timeMemory
84910ToadDaveskiGift (IZhO18_nicegift)C++14
49 / 100
2071 ms80556 KiB
#include <bits/stdc++.h> #define ll long long #define fr first #define sc second using namespace std; vector <vector <pair <ll,ll> > > q; ll a[2000001]; map <ll,ll> poz; vector <ll> ans; int main() { ios_base::sync_with_stdio(0); ll n,k,i,j,ma=0; cin>>n>>k; ll sum=0,part; for(i=1;i<=n;i++) { cin>>a[i]; sum+=a[i]; ma=max(ma,a[i]); } part=sum/k; if (sum%k || part<ma ) { cout<<-1; return 0; } sum=0; vector <pair <ll,ll> > temp; for(i=1;i<=n;i++) { sum+=a[i]; if (sum>=part) { temp.push_back({a[i]-(sum-part),i}); q.push_back(temp); temp.clear(); sum=sum-part; if (sum) temp.push_back({sum,i}); } else { temp.push_back({a[i],i}); } } while(true) { ll mi=1e18; for(i=0;i<k;i++) mi=min(mi,q[i][poz[i]].fr); ans.push_back(mi); ll kol=0; for(i=0;i<k;i++) { ans.push_back(q[i][poz[i]].sc); q[i][poz[i]].fr-=mi; if (poz[i]<q[i].size() && !q[i][poz[i]].fr) { poz[i]++; if (poz[i]<q[i].size()) kol++; } } if (!kol) break; } ll toad=0; cout<<ans.size()/(k+1)<<endl; while(toad<ans.size()) { cout<<ans[toad]<<" "; if (((toad+1)%(k+1))==0) cout<<endl; toad++; } return 0; }

Compilation message (stderr)

nicegift.cpp: In function 'int main()':
nicegift.cpp:57:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (poz[i]<q[i].size() && !q[i][poz[i]].fr)
nicegift.cpp:60:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if (poz[i]<q[i].size()) kol++;
nicegift.cpp:68:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(toad<ans.size())
           ~~~~^~~~~~~~~~~
nicegift.cpp:13:14: warning: unused variable 'j' [-Wunused-variable]
     ll n,k,i,j,ma=0;
              ^
#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...