This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
using namespace std;
using ll = long long;
using pii = pair <int, int>;
#define pb push_back
const int maxN = 1e6 + 10;
const int maxOP = 3e6;
int n, k;
int a[maxN];
priority_queue <pii> PQ;
vector <vector <int>> e;
void Init(){
cin >> n >> k;
ll sum = 0;
for (int i = 1; i <= n; ++i){
cin >> a[i];
sum += a[i];
PQ.push({a[i], i});
}
if (sum % k || PQ.top().fi > sum / k){
cout << -1; return;
}
while (sum){
vector <int> pos;
for (int j = 0; j < k; ++j){
pos.pb(PQ.top().se);
PQ.pop();
}
int add = a[pos.back()];
add = min(add, sum / k - PQ.top().fi);
if (!add) break;
sum -= add * k;
e.pb({add});
for (int j = 0; j < k; ++j){
e.back().pb(pos[j]);
a[pos[j]] -= add;
PQ.push({a[pos[j]], pos[j]});
}
}
cout << e.size() << "\n";
for (auto &i: e){
for (auto &j: i) cout << j << " ";
cout << "\n";
}
}
signed main() {
Init();
}
# | 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... |