# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
133828 | Kastanda | Gift (IZhO18_nicegift) | C++11 | 1251 ms | 73260 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// ItnoE
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1000006;
int n, k;
ll SM, A[N];
vector < ll > R;
priority_queue < pair < ll , int > > Pq;
int main()
{
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i ++)
{
scanf("%lld", &A[i]);
Pq.push({A[i], i});
SM += A[i];
}
if (SM % k || Pq.top().first > SM / k)
return !printf("-1\n");
SM /= k;
while (Pq.top().first)
{
vector < int > vec;
for (int i = 0; i < k; i ++)
vec.push_back(Pq.top().second), Pq.pop();
ll Mx = Pq.size() ? Pq.top().first : 0LL;
ll X = min(A[vec.back()], SM - Mx);
R.push_back(X); SM -= X;
for (int i = 0; i < k; i ++)
A[vec[i]] -= X, Pq.push({A[vec[i]], vec[i]}), R.push_back(vec[i]);
}
printf("%d\n", (int)R.size() / (k + 1));
for (int i = 0; i < (int)R.size(); i ++)
{
printf("%lld ", R[i]);
if ((i + 1) % (k + 1) == 0)
printf("\n");
}
return 0;
}
Compilation message (stderr)
# | 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... |