#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define fi first
#define se second
#define ll long long
using namespace std;
const int N = 1e5 + 7;
const int M = 23;
const int mod = 998244353;
int n,k;
int a[N];
set < pair < int , int > > s;
void solve1()
{
cin >> n >> k;
for( int i = 1; i <= n; i++ ){
cin >> a[i];
s.insert({a[i] , i});
}
int ans = 0;
while( !s.empty() ){
if( (int)s.size() < k ){
cout << -1;
return;
}
int sz = 1;
vector < pair < int , int > > v;
while( sz <= k ){
auto x = *--s.end();
s.erase(--s.end());
x.fi--;
v.push_back(x);
sz++;
}
ans++;
for( auto x : v ){
if( x.fi > 0 )s.insert(x);
}
}
for( int i = 1; i <= n; i++ ){
s.insert({a[i] , i});
}
cout << ans << "\n";
while( !s.empty() ){
int sz = 1;
vector < pair < int , int > > v;
cout << 1 << " ";
while( sz <= k ){
auto x = *--s.end();
s.erase(--s.end());
x.fi--;
cout << x.se << " ";
v.push_back(x);
sz++;
}
cout << "\n";
for( auto x : v ){
if( x.fi > 0 )s.insert(x);
}
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen( "input.txt" , "r" , stdin );
//freopen( "output.txt" , "w" , stdout );
int cghf = 1;//cin >> cghf;
while( cghf-- ){
solve1();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
376 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
420 KB |
n=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
376 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
420 KB |
n=2 |
7 |
Correct |
2 ms |
376 KB |
n=5 |
8 |
Correct |
4 ms |
376 KB |
n=8 |
9 |
Correct |
13 ms |
504 KB |
n=14 |
10 |
Correct |
8 ms |
376 KB |
n=11 |
11 |
Correct |
67 ms |
3704 KB |
n=50000 |
12 |
Correct |
71 ms |
3708 KB |
n=50000 |
13 |
Correct |
40 ms |
760 KB |
n=10 |
14 |
Correct |
44 ms |
888 KB |
n=685 |
15 |
Correct |
60 ms |
1016 KB |
n=623 |
16 |
Correct |
30 ms |
760 KB |
n=973 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
376 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
420 KB |
n=2 |
7 |
Correct |
2 ms |
376 KB |
n=5 |
8 |
Correct |
4 ms |
376 KB |
n=8 |
9 |
Correct |
13 ms |
504 KB |
n=14 |
10 |
Correct |
8 ms |
376 KB |
n=11 |
11 |
Correct |
67 ms |
3704 KB |
n=50000 |
12 |
Correct |
71 ms |
3708 KB |
n=50000 |
13 |
Correct |
40 ms |
760 KB |
n=10 |
14 |
Correct |
44 ms |
888 KB |
n=685 |
15 |
Correct |
60 ms |
1016 KB |
n=623 |
16 |
Correct |
30 ms |
760 KB |
n=973 |
17 |
Correct |
53 ms |
932 KB |
n=989 |
18 |
Correct |
24 ms |
632 KB |
n=563 |
19 |
Correct |
40 ms |
732 KB |
n=592 |
20 |
Correct |
42 ms |
852 KB |
n=938 |
21 |
Correct |
33 ms |
632 KB |
n=747 |
22 |
Correct |
36 ms |
760 KB |
n=991 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
39 ms |
10552 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
376 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
420 KB |
n=2 |
7 |
Correct |
2 ms |
376 KB |
n=5 |
8 |
Correct |
4 ms |
376 KB |
n=8 |
9 |
Correct |
13 ms |
504 KB |
n=14 |
10 |
Correct |
8 ms |
376 KB |
n=11 |
11 |
Correct |
67 ms |
3704 KB |
n=50000 |
12 |
Correct |
71 ms |
3708 KB |
n=50000 |
13 |
Correct |
40 ms |
760 KB |
n=10 |
14 |
Correct |
44 ms |
888 KB |
n=685 |
15 |
Correct |
60 ms |
1016 KB |
n=623 |
16 |
Correct |
30 ms |
760 KB |
n=973 |
17 |
Correct |
53 ms |
932 KB |
n=989 |
18 |
Correct |
24 ms |
632 KB |
n=563 |
19 |
Correct |
40 ms |
732 KB |
n=592 |
20 |
Correct |
42 ms |
852 KB |
n=938 |
21 |
Correct |
33 ms |
632 KB |
n=747 |
22 |
Correct |
36 ms |
760 KB |
n=991 |
23 |
Runtime error |
39 ms |
10552 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
24 |
Halted |
0 ms |
0 KB |
- |