Submission #169401

#TimeUsernameProblemLanguageResultExecution timeMemory
169401RafaelSusGift (IZhO18_nicegift)C++14
7 / 100
2090 ms356788 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; typedef long long ll; const ll inf=1e18+18ll; #define pb push_back ll n,k; ll a[N]; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll S=0ll; cin>>n>>k; priority_queue<pair<ll,int>> q; for(int i=0;i<n;i++){ cin>>a[i]; q.push({a[i],i}); S+=a[i]; } if(S%k||q.top().first>S/k){cout<<"-1\n";return 0;} S/=k; vector<vector<int>> answ; ll cnt=0ll; while(q.top().first){ pair<ll,int>tmp[k]; //if(q.size()<k){cout<<"-1\n";return 0;} for(int i=0;i<k;i++){ tmp[i]=q.top(); q.pop(); } vector<int> an; ll mx=q.size()?q.top().first:0ll; ll x=min(tmp[k-1].first,S-mx); an.push_back(x); for(int i=0;i<k;i++){ tmp[i].first-=x;q.push(tmp[i]); an.push_back(tmp[i].second+1); } cnt+=(ll)an.size(); //if(cnt>=3*1e6){cout<<"-1";return 0;} answ.push_back(an); } cout<<answ.size()<<'\n'; for(int i=0;i<answ.size();i++){ for(int j=0;j<answ[i].size();j++){ cout<<answ[i][j]<<' '; } cout<<'\n'; } }

Compilation message (stderr)

nicegift.cpp: In function 'int main()':
nicegift.cpp:46:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<answ.size();i++){
               ~^~~~~~~~~~~~
nicegift.cpp:47:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j=0;j<answ[i].size();j++){
                 ~^~~~~~~~~~~~~~~
#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...