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;
int main()
{
cin.tie(0)->sync_with_stdio(0);
int n, K; cin >> n >> K;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
priority_queue<pair<int, int>> pq;
for (int i = 0; i < n; i++)
pq.emplace(a[i], i);
vector<vector<int>> ans;
while (pq.size())
{
vector<pair<int, int>> res;
for (int i = 0; i < K; i++)
{
if (pq.empty())
{
cout << -1 << '\n';
return 0;
}
auto x = pq.top();
pq.pop();
x.first--;
res.push_back(x);
}
ans.emplace_back();
for (int i = 0; i < K; i++)
{
ans.back().push_back(res[i].second);
if (res[i].first > 0)
pq.push(res[i]);
}
}
cout << ans.size() << '\n';
for (auto &vec : ans)
{
cout << 1 << ' ';
for (int j = 0; j < K; j++)
cout << vec[j] + 1 << " \n"[j == K - 1];
}
return 0;
}
# | 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... |