#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;
vector<int> pos;
int cnt = 0;
while ((int)Q.size() >= K) {
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;
}
cnt += K;
if (cnt > 3000000) {
cout << "-1\n", exit(0);
}
}
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";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Taken too much stones from the heap |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Taken too much stones from the heap |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Taken too much stones from the heap |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
589 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Taken too much stones from the heap |
2 |
Halted |
0 ms |
0 KB |
- |