#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pl = pair<ll,ll>;
using pii = pair<int,int>;
using tpl = tuple<int,int,int>;
#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k; cin >> n >> k;
    vector<ll> a(n);
    for (ll &u : a) cin >> u;
    ll sum = accumulate(all(a), 0LL);
    if (sum % k) return cout << -1 << "\n", 0;
    priority_queue<pii> pq;
    for (int i = 0; i < n; i++) pq.emplace(a[i], i);
    vector<pair<int,vector<int>>> opr;
    while (pq.size()) {
        vector<int> pos; vector<pii> wait;
        for (int j = 0; j < k; j++) {
            if (pq.empty()) return cout << -1 << "\n", 0;
            wait.push_back(pq.top()), pq.pop();
        }
        int amount = wait.back().first;
        for (auto [a, b] : wait) {
            pos.push_back(b + 1);
            if (a - amount > 0) pq.emplace(a - amount, b);
        }
        opr.emplace_back(amount, pos);
    }
    cout << opr.size() << "\n";
    for (auto [a, vec] : opr) {
        cout << a << " ";
        for (int u : vec) cout << u << " ";
        cout << "\n";
    }
    return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |