#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using ld = long double;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const ll LINF = 2e18;
const double EPS = 1e-9;
#define EMT ios::sync_with_stdio(0); cin.tie(0);
signed main() { EMT
int n, k;
cin >> n >> k;
ll s = 0;
vector<int> arr(n);
priority_queue<pair<int, int>> pq;
for(int i = 0; i < n; i++)
cin >> arr[i], pq.push({arr[i], i});
for(int i = 0; i < n; i++)
s += arr[i];
//if(*max_element(arr.begin(), arr.end()) == *min_element(arr.begin(), arr.end())) {
//if(
//}
vector<pair<int, vector<int>>> ans;
auto get = [&]() {
if(pq.empty())
return -1;
int w = pq.top().second;
pq.pop();
return w;
};
while(!pq.empty()) {
vector<int> tmp(k);
for(int i = 0; i < k; i++)
tmp[i] = get();
if(tmp.back() < 0)
return cout << "-1\n", 0;
ans.push_back({1, tmp});
for(int a : tmp) {
arr[a]--;
if(arr[a])
pq.push({arr[a], a});
}
}
cout << ans.size() << '\n';
for(const auto &[x, y] : ans) {
cout << x;
for(int a : y)
cout << ' ' << a + 1;
cout << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
1 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
1 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
7 |
Correct |
1 ms |
492 KB |
n=5 |
8 |
Correct |
3 ms |
1132 KB |
n=8 |
9 |
Correct |
8 ms |
1384 KB |
n=14 |
10 |
Correct |
5 ms |
1132 KB |
n=11 |
11 |
Correct |
37 ms |
4836 KB |
n=50000 |
12 |
Correct |
36 ms |
4860 KB |
n=50000 |
13 |
Correct |
23 ms |
3936 KB |
n=10 |
14 |
Correct |
24 ms |
3424 KB |
n=685 |
15 |
Correct |
27 ms |
3676 KB |
n=623 |
16 |
Correct |
15 ms |
2144 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
1 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
7 |
Correct |
1 ms |
492 KB |
n=5 |
8 |
Correct |
3 ms |
1132 KB |
n=8 |
9 |
Correct |
8 ms |
1384 KB |
n=14 |
10 |
Correct |
5 ms |
1132 KB |
n=11 |
11 |
Correct |
37 ms |
4836 KB |
n=50000 |
12 |
Correct |
36 ms |
4860 KB |
n=50000 |
13 |
Correct |
23 ms |
3936 KB |
n=10 |
14 |
Correct |
24 ms |
3424 KB |
n=685 |
15 |
Correct |
27 ms |
3676 KB |
n=623 |
16 |
Correct |
15 ms |
2144 KB |
n=973 |
17 |
Correct |
23 ms |
2788 KB |
n=989 |
18 |
Correct |
11 ms |
1128 KB |
n=563 |
19 |
Correct |
18 ms |
1384 KB |
n=592 |
20 |
Correct |
18 ms |
1384 KB |
n=938 |
21 |
Correct |
15 ms |
1256 KB |
n=747 |
22 |
Correct |
19 ms |
1384 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2105 ms |
406260 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
1 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
7 |
Correct |
1 ms |
492 KB |
n=5 |
8 |
Correct |
3 ms |
1132 KB |
n=8 |
9 |
Correct |
8 ms |
1384 KB |
n=14 |
10 |
Correct |
5 ms |
1132 KB |
n=11 |
11 |
Correct |
37 ms |
4836 KB |
n=50000 |
12 |
Correct |
36 ms |
4860 KB |
n=50000 |
13 |
Correct |
23 ms |
3936 KB |
n=10 |
14 |
Correct |
24 ms |
3424 KB |
n=685 |
15 |
Correct |
27 ms |
3676 KB |
n=623 |
16 |
Correct |
15 ms |
2144 KB |
n=973 |
17 |
Correct |
23 ms |
2788 KB |
n=989 |
18 |
Correct |
11 ms |
1128 KB |
n=563 |
19 |
Correct |
18 ms |
1384 KB |
n=592 |
20 |
Correct |
18 ms |
1384 KB |
n=938 |
21 |
Correct |
15 ms |
1256 KB |
n=747 |
22 |
Correct |
19 ms |
1384 KB |
n=991 |
23 |
Execution timed out |
2105 ms |
406260 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |