# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
41576 | cheater2k | Gift (IZhO18_nicegift) | C++14 | 156 ms | 30652 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.
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int n, k;
long long a[N];
long long sum;
vector < vector <int> > vres;
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; ++i) {
cin >> a[i], sum += a[i];
}
assert(sum <= 1e5);
if (sum % k != 0) return printf("-1\n"), 0;
priority_queue < pair<int,int> > pq;
for (int i = 1; i <= n; ++i) pq.push(make_pair(a[i], i));
while(!pq.empty()) {
int taken = 0;
vector<int> cur;
while(!pq.empty() && taken < k) {
int pos = pq.top().second; pq.pop();
cur.push_back(pos);
--a[pos];
++taken;
}
if (taken != k) return printf("-1\n"), 0;
for (int pos : cur) {
if (a[pos]) {
pq.push(make_pair(a[pos], pos));
}
}
vres.push_back(cur);
}
printf("%d\n", vres.size());
for (auto &v : vres) {
printf("1 "); // X
for (int &pos : v) printf("%d ", pos); printf("\n");
}
}
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... |