#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int inf = 1e9;
void solve() {
int n, k;
cin >> n >> k;
vector<ll> a(n);
for (ll &x: a) cin >> x;
if (accumulate(a.begin(), a.end(), 0ll) <= 1e5) {
priority_queue<pair<ll, int>> pq;
for (int i = 0; i < n; i++) pq.emplace(a[i], i);
vector<vector<int>> ans;
while (pq.size() >= k) {
vector<pair<int, int>> v;
vector<int> add = {1};
for (int i = 0; i < k; i++) {
v.emplace_back(pq.top());
add.emplace_back(v.back().second + 1);
pq.pop();
}
for (auto [x, i]: v) {
if (x > 1) pq.emplace(x - 1, i);
}
ans.emplace_back(add);
}
if (!pq.empty()) {
cout << -1;
return;
}
cout << ans.size() << '\n';
for (auto v: ans) {
for (int x: v) cout << x << ' ';
cout << '\n';
}
return;
}
}
int main() {
cin.tie(0)->sync_with_stdio(false);
#ifdef sunnatov
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int queries = 1;
// cin >> queries;
for (int test_case = 1; test_case <= queries; test_case++) {
#ifdef sunnatov
cout << "Test case: " << test_case << endl;
#endif
solve();
cout << '\n';
}
}
Compilation message
nicegift.cpp: In function 'void solve()':
nicegift.cpp:15:26: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
15 | while (pq.size() >= k) {
| ~~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n=4 |
2 |
Correct |
0 ms |
356 KB |
n=3 |
3 |
Correct |
0 ms |
456 KB |
n=3 |
4 |
Correct |
0 ms |
608 KB |
n=4 |
5 |
Correct |
0 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n=4 |
2 |
Correct |
0 ms |
356 KB |
n=3 |
3 |
Correct |
0 ms |
456 KB |
n=3 |
4 |
Correct |
0 ms |
608 KB |
n=4 |
5 |
Correct |
0 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
7 |
Correct |
1 ms |
348 KB |
n=5 |
8 |
Correct |
2 ms |
1020 KB |
n=8 |
9 |
Correct |
8 ms |
1176 KB |
n=14 |
10 |
Correct |
4 ms |
1116 KB |
n=11 |
11 |
Correct |
28 ms |
5084 KB |
n=50000 |
12 |
Correct |
30 ms |
5188 KB |
n=50000 |
13 |
Correct |
20 ms |
3536 KB |
n=10 |
14 |
Correct |
22 ms |
3076 KB |
n=685 |
15 |
Correct |
23 ms |
3340 KB |
n=623 |
16 |
Correct |
13 ms |
2156 KB |
n=973 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n=4 |
2 |
Correct |
0 ms |
356 KB |
n=3 |
3 |
Correct |
0 ms |
456 KB |
n=3 |
4 |
Correct |
0 ms |
608 KB |
n=4 |
5 |
Correct |
0 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
7 |
Correct |
1 ms |
348 KB |
n=5 |
8 |
Correct |
2 ms |
1020 KB |
n=8 |
9 |
Correct |
8 ms |
1176 KB |
n=14 |
10 |
Correct |
4 ms |
1116 KB |
n=11 |
11 |
Correct |
28 ms |
5084 KB |
n=50000 |
12 |
Correct |
30 ms |
5188 KB |
n=50000 |
13 |
Correct |
20 ms |
3536 KB |
n=10 |
14 |
Correct |
22 ms |
3076 KB |
n=685 |
15 |
Correct |
23 ms |
3340 KB |
n=623 |
16 |
Correct |
13 ms |
2156 KB |
n=973 |
17 |
Correct |
22 ms |
2568 KB |
n=989 |
18 |
Correct |
10 ms |
1116 KB |
n=563 |
19 |
Correct |
15 ms |
1456 KB |
n=592 |
20 |
Correct |
15 ms |
1284 KB |
n=938 |
21 |
Correct |
16 ms |
1116 KB |
n=747 |
22 |
Correct |
14 ms |
1116 KB |
n=991 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
92 ms |
8492 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n=4 |
2 |
Correct |
0 ms |
356 KB |
n=3 |
3 |
Correct |
0 ms |
456 KB |
n=3 |
4 |
Correct |
0 ms |
608 KB |
n=4 |
5 |
Correct |
0 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
7 |
Correct |
1 ms |
348 KB |
n=5 |
8 |
Correct |
2 ms |
1020 KB |
n=8 |
9 |
Correct |
8 ms |
1176 KB |
n=14 |
10 |
Correct |
4 ms |
1116 KB |
n=11 |
11 |
Correct |
28 ms |
5084 KB |
n=50000 |
12 |
Correct |
30 ms |
5188 KB |
n=50000 |
13 |
Correct |
20 ms |
3536 KB |
n=10 |
14 |
Correct |
22 ms |
3076 KB |
n=685 |
15 |
Correct |
23 ms |
3340 KB |
n=623 |
16 |
Correct |
13 ms |
2156 KB |
n=973 |
17 |
Correct |
22 ms |
2568 KB |
n=989 |
18 |
Correct |
10 ms |
1116 KB |
n=563 |
19 |
Correct |
15 ms |
1456 KB |
n=592 |
20 |
Correct |
15 ms |
1284 KB |
n=938 |
21 |
Correct |
16 ms |
1116 KB |
n=747 |
22 |
Correct |
14 ms |
1116 KB |
n=991 |
23 |
Incorrect |
92 ms |
8492 KB |
Unexpected end of file - int32 expected |
24 |
Halted |
0 ms |
0 KB |
- |