This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |