Submission #483401

#TimeUsernameProblemLanguageResultExecution timeMemory
483401mosiashvililukaGift (IZhO18_nicegift)C++14
30 / 100
2100 ms254224 KiB
#include<bits/stdc++.h> using namespace std; long long a,b,c,d,e,i,j,ii,jj,zx,xc,k,f[1000009]; vector <vector <long long> > ans; vector <long long> vv; multiset <pair <long long, long long> > s; multiset <pair <long long, long long> >::iterator it; int main(){ ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>a>>k;zx=0; for(i=1; i<=a; i++){ cin>>f[i]; s.insert(make_pair(f[i],i)); zx+=f[i]; } if(zx%k!=0){ cout<<-1;exit(0); } while(s.size()>=k){ c=1;it=s.end();vv.clear(); while(c<=k){ it--; vv.push_back((*it).second);c++; } ans.push_back(vv);c=1; while(c<=k){ it=s.end();it--; s.erase(it);c++; } for(i=0; i<vv.size(); i++){ f[vv[i]]--; if(f[vv[i]]>0) s.insert(make_pair(f[vv[i]],vv[i])); } } if(s.size()!=0){ cout<<-1;exit(0); } cout<<ans.size()<<"\n"; for(i=0; i<ans.size(); i++){ cout<<"1 "; for(j=0; j<k; j++){ cout<<ans[i][j]<<" "; } cout<<"\n"; } return 0; }

Compilation message (stderr)

nicegift.cpp: In function 'int main()':
nicegift.cpp:19:16: warning: comparison of integer expressions of different signedness: 'std::multiset<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   19 |  while(s.size()>=k){
      |        ~~~~~~~~^~~
nicegift.cpp:30:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |   for(i=0; i<vv.size(); i++){
      |            ~^~~~~~~~~~
nicegift.cpp:39:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |  for(i=0; i<ans.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...