#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=1e9;
ll n, k, x, s, mx, mn=INF, o;
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;
}
}
}
int 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
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
0 ms |
364 KB |
n=3 |
3 |
Correct |
0 ms |
364 KB |
n=3 |
4 |
Correct |
0 ms |
364 KB |
n=4 |
5 |
Correct |
0 ms |
364 KB |
n=4 |
6 |
Correct |
0 ms |
364 KB |
n=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
0 ms |
364 KB |
n=3 |
3 |
Correct |
0 ms |
364 KB |
n=3 |
4 |
Correct |
0 ms |
364 KB |
n=4 |
5 |
Correct |
0 ms |
364 KB |
n=4 |
6 |
Correct |
0 ms |
364 KB |
n=2 |
7 |
Correct |
0 ms |
364 KB |
n=5 |
8 |
Correct |
1 ms |
364 KB |
n=8 |
9 |
Correct |
7 ms |
492 KB |
n=14 |
10 |
Correct |
4 ms |
384 KB |
n=11 |
11 |
Correct |
32 ms |
1652 KB |
n=50000 |
12 |
Correct |
32 ms |
1644 KB |
n=50000 |
13 |
Correct |
19 ms |
748 KB |
n=10 |
14 |
Correct |
21 ms |
896 KB |
n=685 |
15 |
Correct |
22 ms |
876 KB |
n=623 |
16 |
Correct |
12 ms |
620 KB |
n=973 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
0 ms |
364 KB |
n=3 |
3 |
Correct |
0 ms |
364 KB |
n=3 |
4 |
Correct |
0 ms |
364 KB |
n=4 |
5 |
Correct |
0 ms |
364 KB |
n=4 |
6 |
Correct |
0 ms |
364 KB |
n=2 |
7 |
Correct |
0 ms |
364 KB |
n=5 |
8 |
Correct |
1 ms |
364 KB |
n=8 |
9 |
Correct |
7 ms |
492 KB |
n=14 |
10 |
Correct |
4 ms |
384 KB |
n=11 |
11 |
Correct |
32 ms |
1652 KB |
n=50000 |
12 |
Correct |
32 ms |
1644 KB |
n=50000 |
13 |
Correct |
19 ms |
748 KB |
n=10 |
14 |
Correct |
21 ms |
896 KB |
n=685 |
15 |
Correct |
22 ms |
876 KB |
n=623 |
16 |
Correct |
12 ms |
620 KB |
n=973 |
17 |
Correct |
21 ms |
876 KB |
n=989 |
18 |
Correct |
10 ms |
620 KB |
n=563 |
19 |
Correct |
17 ms |
768 KB |
n=592 |
20 |
Correct |
17 ms |
748 KB |
n=938 |
21 |
Correct |
14 ms |
620 KB |
n=747 |
22 |
Correct |
15 ms |
748 KB |
n=991 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
472 ms |
16720 KB |
Expected int32, but "500000000000000000" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
0 ms |
364 KB |
n=3 |
3 |
Correct |
0 ms |
364 KB |
n=3 |
4 |
Correct |
0 ms |
364 KB |
n=4 |
5 |
Correct |
0 ms |
364 KB |
n=4 |
6 |
Correct |
0 ms |
364 KB |
n=2 |
7 |
Correct |
0 ms |
364 KB |
n=5 |
8 |
Correct |
1 ms |
364 KB |
n=8 |
9 |
Correct |
7 ms |
492 KB |
n=14 |
10 |
Correct |
4 ms |
384 KB |
n=11 |
11 |
Correct |
32 ms |
1652 KB |
n=50000 |
12 |
Correct |
32 ms |
1644 KB |
n=50000 |
13 |
Correct |
19 ms |
748 KB |
n=10 |
14 |
Correct |
21 ms |
896 KB |
n=685 |
15 |
Correct |
22 ms |
876 KB |
n=623 |
16 |
Correct |
12 ms |
620 KB |
n=973 |
17 |
Correct |
21 ms |
876 KB |
n=989 |
18 |
Correct |
10 ms |
620 KB |
n=563 |
19 |
Correct |
17 ms |
768 KB |
n=592 |
20 |
Correct |
17 ms |
748 KB |
n=938 |
21 |
Correct |
14 ms |
620 KB |
n=747 |
22 |
Correct |
15 ms |
748 KB |
n=991 |
23 |
Incorrect |
472 ms |
16720 KB |
Expected int32, but "500000000000000000" found |
24 |
Halted |
0 ms |
0 KB |
- |