#include<bits/stdc++.h>
using namespace std;
//#pragma gcc optimize("Ofast,unroll-loops")
//#pragma gcc target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native")
//#define int long long
//#define double long double
#define MP make_pair
#define F first
#define S second
#define MOD 1000000007
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int N, K;
cin >> N >> K;
int A;
priority_queue<pair<int, int>> pq;
for (int i = 1; i <= N; i++)
cin >> A, pq.push(MP(A, i));
vector<vector<int>> ans;
while (pq.size() >= K)
{
ans.push_back({1});
vector<pair<int, int>> v;
for (int i = 0; i < K; i++)
ans.back().push_back(pq.top().S), v.push_back(pq.top()), pq.pop();
for (auto &p : v)
{
p.F--;
if (p.F)
pq.push(p);
}
}
if (pq.empty())
{
cout << ans.size() << '\n';
for (auto v : ans)
{
for (int i : v)
cout << i << ' ';
cout << '\n';
}
}
else
cout << "-1\n";
return 0;
}
// * * ***** * * * * **** **** **** ** **
// * * * ** * * * * * * * * * * *
// ***** ***** * * * * * * **** * * * *
// * * * * ** * * * * * * ***** *
// * * ***** * * *** **** * * **** * *****
// ***** ***** * * * ***** * * ***** *****
// * * * * * * * ** * * * *
// * * * ***** * * * * * * *****
// * * * * * * * * ** * *
// **** ***** * ***** ***** * * * *
Compilation message
nicegift.cpp: In function 'int main()':
nicegift.cpp:27:22: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
27 | while (pq.size() >= K)
| ~~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
0 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
0 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
0 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
0 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
7 |
Correct |
1 ms |
364 KB |
n=5 |
8 |
Correct |
3 ms |
1004 KB |
n=8 |
9 |
Correct |
9 ms |
1192 KB |
n=14 |
10 |
Correct |
6 ms |
1004 KB |
n=11 |
11 |
Correct |
42 ms |
4324 KB |
n=50000 |
12 |
Correct |
42 ms |
4324 KB |
n=50000 |
13 |
Correct |
30 ms |
3488 KB |
n=10 |
14 |
Correct |
38 ms |
3104 KB |
n=685 |
15 |
Correct |
32 ms |
3360 KB |
n=623 |
16 |
Correct |
18 ms |
2084 KB |
n=973 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
0 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
0 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
7 |
Correct |
1 ms |
364 KB |
n=5 |
8 |
Correct |
3 ms |
1004 KB |
n=8 |
9 |
Correct |
9 ms |
1192 KB |
n=14 |
10 |
Correct |
6 ms |
1004 KB |
n=11 |
11 |
Correct |
42 ms |
4324 KB |
n=50000 |
12 |
Correct |
42 ms |
4324 KB |
n=50000 |
13 |
Correct |
30 ms |
3488 KB |
n=10 |
14 |
Correct |
38 ms |
3104 KB |
n=685 |
15 |
Correct |
32 ms |
3360 KB |
n=623 |
16 |
Correct |
18 ms |
2084 KB |
n=973 |
17 |
Correct |
29 ms |
2596 KB |
n=989 |
18 |
Correct |
13 ms |
1260 KB |
n=563 |
19 |
Correct |
19 ms |
1516 KB |
n=592 |
20 |
Correct |
20 ms |
1388 KB |
n=938 |
21 |
Correct |
16 ms |
1388 KB |
n=747 |
22 |
Correct |
17 ms |
1280 KB |
n=991 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2094 ms |
336720 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
0 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
0 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
7 |
Correct |
1 ms |
364 KB |
n=5 |
8 |
Correct |
3 ms |
1004 KB |
n=8 |
9 |
Correct |
9 ms |
1192 KB |
n=14 |
10 |
Correct |
6 ms |
1004 KB |
n=11 |
11 |
Correct |
42 ms |
4324 KB |
n=50000 |
12 |
Correct |
42 ms |
4324 KB |
n=50000 |
13 |
Correct |
30 ms |
3488 KB |
n=10 |
14 |
Correct |
38 ms |
3104 KB |
n=685 |
15 |
Correct |
32 ms |
3360 KB |
n=623 |
16 |
Correct |
18 ms |
2084 KB |
n=973 |
17 |
Correct |
29 ms |
2596 KB |
n=989 |
18 |
Correct |
13 ms |
1260 KB |
n=563 |
19 |
Correct |
19 ms |
1516 KB |
n=592 |
20 |
Correct |
20 ms |
1388 KB |
n=938 |
21 |
Correct |
16 ms |
1388 KB |
n=747 |
22 |
Correct |
17 ms |
1280 KB |
n=991 |
23 |
Execution timed out |
2094 ms |
336720 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |