#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair <int, int>
#define fi first
#define se second
#define mp make_pair
#define isz(a) (int)(a).size()
const int NM = 1e5;
int N, K, a[NM+5];
priority_queue <pii> Q;
vector <pii> v;
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> K;
for (int i = 1; i <= N; i++){
cin >> a[i];
Q.push(mp(a[i], i));
}
while (!Q.empty()){
if (isz(Q) < K){
cout << -1;
return 0;
}
for (int i = 1; i <= K; i++){
pii P = Q.top();
v.push_back(P);
Q.pop();
}
for (int i = isz(v)-1; i >= isz(v)-K; i--){
pii P = v[i];
P.fi--;
if (P.fi > 0) Q.push(P);
}
}
cout << isz(v)/K << '\n';
while (!v.empty()){
cout << 1 << ' ';
for (int i = 1; i <= K; i++){
cout << v.back().se << ' ';
v.pop_back();
}
cout << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
n=4 |
2 |
Correct |
1 ms |
344 KB |
n=3 |
3 |
Correct |
1 ms |
344 KB |
n=3 |
4 |
Correct |
1 ms |
348 KB |
n=4 |
5 |
Correct |
1 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
n=4 |
2 |
Correct |
1 ms |
344 KB |
n=3 |
3 |
Correct |
1 ms |
344 KB |
n=3 |
4 |
Correct |
1 ms |
348 KB |
n=4 |
5 |
Correct |
1 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
7 |
Correct |
1 ms |
600 KB |
n=5 |
8 |
Correct |
1 ms |
992 KB |
n=8 |
9 |
Correct |
4 ms |
992 KB |
n=14 |
10 |
Correct |
3 ms |
988 KB |
n=11 |
11 |
Correct |
21 ms |
4176 KB |
n=50000 |
12 |
Correct |
20 ms |
4172 KB |
n=50000 |
13 |
Correct |
12 ms |
2772 KB |
n=10 |
14 |
Correct |
15 ms |
2784 KB |
n=685 |
15 |
Correct |
16 ms |
3552 KB |
n=623 |
16 |
Correct |
9 ms |
1616 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
n=4 |
2 |
Correct |
1 ms |
344 KB |
n=3 |
3 |
Correct |
1 ms |
344 KB |
n=3 |
4 |
Correct |
1 ms |
348 KB |
n=4 |
5 |
Correct |
1 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
7 |
Correct |
1 ms |
600 KB |
n=5 |
8 |
Correct |
1 ms |
992 KB |
n=8 |
9 |
Correct |
4 ms |
992 KB |
n=14 |
10 |
Correct |
3 ms |
988 KB |
n=11 |
11 |
Correct |
21 ms |
4176 KB |
n=50000 |
12 |
Correct |
20 ms |
4172 KB |
n=50000 |
13 |
Correct |
12 ms |
2772 KB |
n=10 |
14 |
Correct |
15 ms |
2784 KB |
n=685 |
15 |
Correct |
16 ms |
3552 KB |
n=623 |
16 |
Correct |
9 ms |
1616 KB |
n=973 |
17 |
Correct |
17 ms |
2528 KB |
n=989 |
18 |
Correct |
9 ms |
1764 KB |
n=563 |
19 |
Correct |
16 ms |
2544 KB |
n=592 |
20 |
Correct |
14 ms |
2784 KB |
n=938 |
21 |
Correct |
11 ms |
2528 KB |
n=747 |
22 |
Correct |
13 ms |
2728 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
18 ms |
7124 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
n=4 |
2 |
Correct |
1 ms |
344 KB |
n=3 |
3 |
Correct |
1 ms |
344 KB |
n=3 |
4 |
Correct |
1 ms |
348 KB |
n=4 |
5 |
Correct |
1 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
7 |
Correct |
1 ms |
600 KB |
n=5 |
8 |
Correct |
1 ms |
992 KB |
n=8 |
9 |
Correct |
4 ms |
992 KB |
n=14 |
10 |
Correct |
3 ms |
988 KB |
n=11 |
11 |
Correct |
21 ms |
4176 KB |
n=50000 |
12 |
Correct |
20 ms |
4172 KB |
n=50000 |
13 |
Correct |
12 ms |
2772 KB |
n=10 |
14 |
Correct |
15 ms |
2784 KB |
n=685 |
15 |
Correct |
16 ms |
3552 KB |
n=623 |
16 |
Correct |
9 ms |
1616 KB |
n=973 |
17 |
Correct |
17 ms |
2528 KB |
n=989 |
18 |
Correct |
9 ms |
1764 KB |
n=563 |
19 |
Correct |
16 ms |
2544 KB |
n=592 |
20 |
Correct |
14 ms |
2784 KB |
n=938 |
21 |
Correct |
11 ms |
2528 KB |
n=747 |
22 |
Correct |
13 ms |
2728 KB |
n=991 |
23 |
Runtime error |
18 ms |
7124 KB |
Execution killed with signal 11 |
24 |
Halted |
0 ms |
0 KB |
- |