#include <bits/stdc++.h>
#define all(i) i.begin(), i.end()
#define rall(i) i.rbegin(), i.rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, int> pl;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n, k;
cin >> n >> k;
ll a[n], sum = 0, mx = 0;
priority_queue<pl> pq;
for (int i = 0; i < n; ++i) cin >> a[i], sum += a[i], mx = max(mx, a[i]), pq.emplace(a[i], i);
if (sum % k != 0 || mx > sum / k) return cout << -1, 0;
vector<int> v;
vector<vector<int>> ans;
while (sum > 0) {
for (int i = 0; i < k; ++i)
v.push_back(pq.top().second), pq.pop();
if (a[v.back()] == sum / k) {
ans.emplace_back(1, sum / k);
for (int i : v) ans.back().push_back(i + 1);
break;
}
ll x = max(1ll, a[v.back()] - pq.top().first);
ans.emplace_back(1, x);
while (!v.empty()) {
int i = v.back();
v.pop_back();
ans.back().push_back(i + 1);
a[i] -= x, sum -= x;
pq.emplace(a[i], i);
}
}
cout << ans.size() << '\n';
for (auto i : ans) {
for (int j : i) cout << j << ' ';
cout << '\n';
}
}
/*
* sum % k == 0 && max <= sum / k
* always sort 321
* every time [0,k), x = max(h[k] - h[k-1], 1)
*/
# |
결과 |
실행 시간 |
메모리 |
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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
364 KB |
n=5 |
8 |
Correct |
1 ms |
364 KB |
n=8 |
9 |
Correct |
8 ms |
1192 KB |
n=14 |
10 |
Correct |
6 ms |
748 KB |
n=11 |
11 |
Correct |
28 ms |
3816 KB |
n=50000 |
12 |
Correct |
39 ms |
4964 KB |
n=50000 |
13 |
Correct |
23 ms |
2852 KB |
n=10 |
14 |
Correct |
34 ms |
3104 KB |
n=685 |
15 |
Correct |
32 ms |
3360 KB |
n=623 |
16 |
Correct |
24 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 |
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 |
364 KB |
n=5 |
8 |
Correct |
1 ms |
364 KB |
n=8 |
9 |
Correct |
8 ms |
1192 KB |
n=14 |
10 |
Correct |
6 ms |
748 KB |
n=11 |
11 |
Correct |
28 ms |
3816 KB |
n=50000 |
12 |
Correct |
39 ms |
4964 KB |
n=50000 |
13 |
Correct |
23 ms |
2852 KB |
n=10 |
14 |
Correct |
34 ms |
3104 KB |
n=685 |
15 |
Correct |
32 ms |
3360 KB |
n=623 |
16 |
Correct |
24 ms |
2084 KB |
n=973 |
17 |
Correct |
29 ms |
2596 KB |
n=989 |
18 |
Correct |
17 ms |
1388 KB |
n=563 |
19 |
Correct |
22 ms |
1644 KB |
n=592 |
20 |
Correct |
22 ms |
1416 KB |
n=938 |
21 |
Correct |
21 ms |
1388 KB |
n=747 |
22 |
Correct |
19 ms |
1260 KB |
n=991 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2085 ms |
344060 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 |
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 |
364 KB |
n=5 |
8 |
Correct |
1 ms |
364 KB |
n=8 |
9 |
Correct |
8 ms |
1192 KB |
n=14 |
10 |
Correct |
6 ms |
748 KB |
n=11 |
11 |
Correct |
28 ms |
3816 KB |
n=50000 |
12 |
Correct |
39 ms |
4964 KB |
n=50000 |
13 |
Correct |
23 ms |
2852 KB |
n=10 |
14 |
Correct |
34 ms |
3104 KB |
n=685 |
15 |
Correct |
32 ms |
3360 KB |
n=623 |
16 |
Correct |
24 ms |
2084 KB |
n=973 |
17 |
Correct |
29 ms |
2596 KB |
n=989 |
18 |
Correct |
17 ms |
1388 KB |
n=563 |
19 |
Correct |
22 ms |
1644 KB |
n=592 |
20 |
Correct |
22 ms |
1416 KB |
n=938 |
21 |
Correct |
21 ms |
1388 KB |
n=747 |
22 |
Correct |
19 ms |
1260 KB |
n=991 |
23 |
Execution timed out |
2085 ms |
344060 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |