This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <vector>
#include <iostream>
#include <queue>
#define MN 1007171
using namespace std;
using ll = long long;
ll n, k, A[MN];
priority_queue<pair<ll, int> > S;
vector<pair<ll, vector<int>>> O;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
ll sum = 0;
for(ll i = 1; i <= n; ++i)
cin >> A[i], S.push({A[i], i}), sum += A[i];
if(S.top().first > sum / k || sum % k) {
cout << "-1\n";
return 0;
}
ll vmin, suma_ramasa, delta;
vector<int> PU;
while(!S.empty()) {
suma_ramasa = sum;
for(ll i = 1; i <= k; ++i)
PU.push_back(S.top().second), suma_ramasa -= S.top().first, S.pop();
if(!S.empty())
delta = min(A[PU.back()], sum / k - S.top().first);
else delta = A[PU.back()];
O.push_back(make_pair(delta, PU));
for(auto it : PU){
A[it] -= delta;
sum -= delta;
if(A[it])
S.push({A[it], it});
}
PU.clear();
}
cout << O.size() << "\n";
for(auto [c, v] : O) {
cout << c << " ";
for(auto it : v)
cout << it << " ";
cout << "\n";
}
return 0;
}
Compilation message (stderr)
nicegift.cpp: In function 'int main()':
nicegift.cpp:26:8: warning: unused variable 'vmin' [-Wunused-variable]
26 | ll vmin, suma_ramasa, delta;
| ^~~~
# | 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... |