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>
#define ll long long
#define pb push_back
#define F first
#define S second
using namespace std;
const ll N=1000006, INF=1e18+2021;
ll n, k, x, s, mx, mn=INF, o, g;
pair<int, int> a[N];
priority_queue<pair<int,int> > q;
int main(){ios_base::sync_with_stdio(false), cin.tie(0);
cin>>n>>k;
for(int i=0;i<n;i++)
cin>>x, s+=x,
mx=max(mx,x),
mn=min(mn,x),
q.push({x,i+1});
if(s%k||k*mx>s){cout<<-1; return 0;}
if(mn==mx){
// int g=__gcd(k, n);
for (int i=1; i<=sqrt(mn); i++){
if(mn%i==0){
if((i*n)%k==0){
x=i;
break;
}
if((mn/i*n)%k==0){
x=mn/i;
}
}
}
g=k/x;
// cout<<g<<endl;
cout<<n/g<<endl;
for (int i=1; i<=n/g; i++){
cout<<mn/x<<" ";
for (int j=o; j<o+k; j++){
cout<<(j%n)+1<<" ";
}cout<<endl;
o+=g;
o%=n;
}
return 0;
}
cout<<s/k<<'\n';
while(!q.empty()){
cout<<1<<" ";
for(int i=0;i<k;i++)
a[i]=q.top(),
q.pop();
for(int i=0;i<k;i++){
if(a[i].F>1)q.push({a[i].F-1, a[i].S});
cout<<a[i].S<<" ";
}
cout<<'\n';
}
}
/*
10 6
6 6 6 6 6 6 6 6 6 6
*/
# | 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... |