#include <bits/stdc++.h>
#ifdef local
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(a...) qqbx(#a, a)
template <typename ...T> void qqbx(const char *s, T ...a) {
int cnt = sizeof...(T);
((std::cerr << "\033[1;32m(" << s << ") = (") , ... , (std::cerr << a << (--cnt ? ", " : ")\033[0m\n")));
}
#else
#define safe ((void)0)
#define debug(...) ((void)0)
#endif // local
#define all(v) begin(v),end(v)
using namespace std;
using ll = int64_t;
template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using max_heap = priority_queue<T, vector<T>, less<T>>;
const int maxn = 100025, inf = 1e9;
const ll INF = 1e18;
ll A[maxn];
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, k;
cin >> n >> k;
max_heap<pair<ll,int>> pq;
for (int i = 1; i <= n; i++) {
cin >> A[i];
pq.emplace(A[i], i);
}
vector<vector<int>> ans;
while (!pq.empty()) {
vector<int> v;
ll x = INF;
for (int t = 0; t < k; t++) {
if (pq.empty()) return cout << -1 << '\n', 0;
auto [y, j] = pq.top(); pq.pop();
v.push_back(j);
x = y;
}
ans.push_back(v);
for (int pos: v) {
A[pos] -= x;
if (A[pos]) pq.emplace(A[pos], pos);
}
}
cout << ans.size() << '\n';
for (auto v: ans) {
for (int i = 0; i < k; i++)
cout << v[i] << (i+1==k ? '\n' : ' ');
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Taken too much stones from the heap |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Taken too much stones from the heap |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Taken too much stones from the heap |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
27 ms |
5476 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Taken too much stones from the heap |
2 |
Halted |
0 ms |
0 KB |
- |