#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N, K;
cin >> N >> K;
vector<long long> A(N);
priority_queue<pair<long long, int>> Q;
long long sum = 0;
for (int i = 0; i < N; i++) {
cin >> A[i];
Q.push({A[i], i});
sum += A[i];
}
vector<vector<long long>> answer;
while ((int)Q.size() >= K) {
vector<int> pos;
long long val = numeric_limits<int>::max();
for (int i = 0; i < K; i++) {
val = min(val, Q.top().first);
pos.push_back(Q.top().second);
Q.pop();
}
if (!Q.empty()) {
val = min(val, sum / K - Q.top().first);
}
answer.push_back({val});
for (int i : pos) {
answer.back().push_back(1 + i);
if ((A[i] -= val) > 0) {
Q.push({A[i], i});
}
sum -= val;
}
}
if (Q.empty()) {
cout << answer.size() << "\n";
for (auto &op : answer) {
for (int i = 0; i <= K; i++) {
cout << op[i] << " \n"[i == K];
}
}
} else {
cout << "-1\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n=4 |
2 |
Correct |
0 ms |
348 KB |
n=3 |
3 |
Correct |
0 ms |
348 KB |
n=3 |
4 |
Correct |
0 ms |
452 KB |
n=4 |
5 |
Correct |
0 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n=4 |
2 |
Correct |
0 ms |
348 KB |
n=3 |
3 |
Correct |
0 ms |
348 KB |
n=3 |
4 |
Correct |
0 ms |
452 KB |
n=4 |
5 |
Correct |
0 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
7 |
Correct |
0 ms |
348 KB |
n=5 |
8 |
Correct |
0 ms |
348 KB |
n=8 |
9 |
Correct |
1 ms |
348 KB |
n=14 |
10 |
Correct |
0 ms |
348 KB |
n=11 |
11 |
Correct |
16 ms |
4156 KB |
n=50000 |
12 |
Correct |
15 ms |
3816 KB |
n=50000 |
13 |
Correct |
1 ms |
348 KB |
n=10 |
14 |
Correct |
1 ms |
348 KB |
n=685 |
15 |
Correct |
0 ms |
348 KB |
n=623 |
16 |
Correct |
1 ms |
348 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n=4 |
2 |
Correct |
0 ms |
348 KB |
n=3 |
3 |
Correct |
0 ms |
348 KB |
n=3 |
4 |
Correct |
0 ms |
452 KB |
n=4 |
5 |
Correct |
0 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
7 |
Correct |
0 ms |
348 KB |
n=5 |
8 |
Correct |
0 ms |
348 KB |
n=8 |
9 |
Correct |
1 ms |
348 KB |
n=14 |
10 |
Correct |
0 ms |
348 KB |
n=11 |
11 |
Correct |
16 ms |
4156 KB |
n=50000 |
12 |
Correct |
15 ms |
3816 KB |
n=50000 |
13 |
Correct |
1 ms |
348 KB |
n=10 |
14 |
Correct |
1 ms |
348 KB |
n=685 |
15 |
Correct |
0 ms |
348 KB |
n=623 |
16 |
Correct |
1 ms |
348 KB |
n=973 |
17 |
Correct |
1 ms |
348 KB |
n=989 |
18 |
Correct |
0 ms |
348 KB |
n=563 |
19 |
Correct |
1 ms |
384 KB |
n=592 |
20 |
Correct |
1 ms |
348 KB |
n=938 |
21 |
Correct |
1 ms |
348 KB |
n=747 |
22 |
Correct |
1 ms |
348 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2070 ms |
479116 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n=4 |
2 |
Correct |
0 ms |
348 KB |
n=3 |
3 |
Correct |
0 ms |
348 KB |
n=3 |
4 |
Correct |
0 ms |
452 KB |
n=4 |
5 |
Correct |
0 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
7 |
Correct |
0 ms |
348 KB |
n=5 |
8 |
Correct |
0 ms |
348 KB |
n=8 |
9 |
Correct |
1 ms |
348 KB |
n=14 |
10 |
Correct |
0 ms |
348 KB |
n=11 |
11 |
Correct |
16 ms |
4156 KB |
n=50000 |
12 |
Correct |
15 ms |
3816 KB |
n=50000 |
13 |
Correct |
1 ms |
348 KB |
n=10 |
14 |
Correct |
1 ms |
348 KB |
n=685 |
15 |
Correct |
0 ms |
348 KB |
n=623 |
16 |
Correct |
1 ms |
348 KB |
n=973 |
17 |
Correct |
1 ms |
348 KB |
n=989 |
18 |
Correct |
0 ms |
348 KB |
n=563 |
19 |
Correct |
1 ms |
384 KB |
n=592 |
20 |
Correct |
1 ms |
348 KB |
n=938 |
21 |
Correct |
1 ms |
348 KB |
n=747 |
22 |
Correct |
1 ms |
348 KB |
n=991 |
23 |
Execution timed out |
2070 ms |
479116 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |