#include<bits/stdc++.h>
#define ll long long
#define fr first
#define se second
using namespace std;
set< pair< ll, ll > > st;
vector< ll > ans;
vector< ll > st4;
int main(){
ll n, k, t4=0;
cin>>n>>k;
for( ll i =1 ; i <= n ; i ++ ){
ll x;
cin>>x;
st.insert({x,i});
st4.push_back(x);
if( st4.size() > 1 && st4[st4.size()-1] != st4[st4.size()-2] ) t4=1;
}
if( t4 == 0 && k > 2 ){
cout<<1/0;
if( st4.size() % k != 0 ) {
cout<<-1;
return 0;
}
else {
cout<<n/k<<endl;
for( ll j = 1; j <= n/k; j ++ ){
co11ut<<st4[0]<<' ';
for(ll i = 1 ; i <= k; i ++ ){
cout<<i*j<<' ';
}
cout<<endl;
}
return 0;
}
}
/***
std::pair<ll,ll> x;
x=*st.rbegin();
st.erase(x);
***/
ans.push_back(-1);
std::vector< pair<ll,ll> > help;
while( st.size()>k-1 ){
ll t = k;
ans.push_back(1);
while( t > 0 ){
std::pair< ll , ll > x;
x=*st.rbegin();
st.erase(*st.rbegin());
///cout<<x.fr<<'#'<<x.se<<endl;
if( x.fr != 1 ) help.push_back({x.fr-1,x.se});
ans.push_back(x.se);
t--;
}
///cout<<help.size()<<'!'<<endl;
if( help.size() != 0 ){
for( ll i = help.size()-1 ; i >= 0 ; i -- ) {
st.insert(help[i]);
}
help.clear();
}
///cout<<st.size()<<endl;
}
if( st.size() < k && st.size()!=0 ){
cout<<-1;
return 0;
}
cout<<(ans.size()-1)/(k+1)<<endl;
for( ll i = 1; i < ans.size(); i ++ ){
cout<<ans[i]<<' ';
if( (i)%(k+1)==0 ) cout<<endl;
}
}
Compilation message
nicegift.cpp: In function 'int main()':
nicegift.cpp:20:11: warning: division by zero [-Wdiv-by-zero]
cout<<1/0;
~^~
nicegift.cpp:28:9: error: 'co11ut' was not declared in this scope
co11ut<<st4[0]<<' ';
^~~~~~
nicegift.cpp:45:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while( st.size()>k-1 ){
~~~~~~~~~^~~~
nicegift.cpp:66:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if( st.size() < k && st.size()!=0 ){
~~~~~~~~~~^~~
nicegift.cpp:71:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for( ll i = 1; i < ans.size(); i ++ ){
~~^~~~~~~~~~~~