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 FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define DEBUG(x) { cerr << #x << '=' << x << endl; }
#define Arr(a, l, r) { cerr << #a << " = {"; FOR(_, l, r) cerr << ' ' << a[_]; cerr << "}\n"; }
#define N 1001000
#define pp pair<int, int>
#define endl '\n'
#define IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define taskname ""
#define bit(S, i) (((S) >> (i)) & 1)
using namespace std;
int n, k, a[N];
priority_queue<pp> heap;
vector<int> res[N];
int main() {
#ifdef NERO
freopen("test.inp","r",stdin);
freopen("test.out","w",stdout);
double stime = clock();
#else
//freopen(taskname".inp","r",stdin);
//freopen(taskname".out","w",stdout);
#endif //NERO
IO;
cin >> n >> k;
FOR(i, 1, n) {
cin >> a[i];
heap.push(pp(a[i], i));
}
int cnt = 0;
while (!heap.empty()) {
++cnt;
if (heap.size() < k) {
cout << -1;
return 0;
}
REP(i, k) {
res[cnt].push_back(heap.top().second);
a[heap.top().second]--;
heap.pop();
}
for (int id : res[cnt]) if (a[id]) heap.push(pp(a[id], id));
}
cout << cnt << '\n';
FOR(i, 1, cnt) {
cout << "1 ";
for (int id : res[i]) cout << id << ' ';
cout << '\n';
}
#ifdef NERO
double etime = clock();
cerr << "Execution time: " << (etime - stime) / CLOCKS_PER_SEC * 1000 << " ms.\n";
#endif // NERO
}
Compilation message (stderr)
nicegift.cpp: In function 'int main()':
nicegift.cpp:36:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (heap.size() < k) {
~~~~~~~~~~~~^~~
# | 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... |