Submission #84941

#TimeUsernameProblemLanguageResultExecution timeMemory
84941ToadDaveskiGift (IZhO18_nicegift)C++11
100 / 100
882 ms94084 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++) { scanf("%lld", 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; temp.clear(); 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; printf("%d\n", ans.size() / (k + 1)); while(toad<ans.size()) { printf("%lld ", ans[toad]); if (((toad+1)%(k+1))==0) puts(""); toad++; } return 0; }

Compilation message (stderr)

nicegift.cpp: In function 'int main()':
nicegift.cpp:58:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (poz[i]<q[i].size() && !q[i][poz[i]].fr)
nicegift.cpp:61:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if (poz[i]<q[i].size()) kol++;
nicegift.cpp:68:40: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long unsigned int' [-Wformat=]
     printf("%d\n", ans.size() / (k + 1));
                    ~~~~~~~~~~~~~~~~~~~~^
nicegift.cpp:69: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;
              ^
nicegift.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", 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...