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;
//#pragma gcc optimize("Ofast,unroll-loops")
//#pragma gcc target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native")
//#define int long long
//#define double long double
#define MP make_pair
#define F first
#define S second
#define MOD 1000000007
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int N, K;
cin >> N >> K;
int A;
priority_queue<pair<int, int>> pq;
for (int i = 1; i <= N; i++)
cin >> A, pq.push(MP(A, i));
vector<vector<int>> ans;
while (pq.size() >= K)
{
ans.push_back({1});
vector<pair<int, int>> v;
for (int i = 0; i < K; i++)
ans.back().push_back(pq.top().S), v.push_back(pq.top()), pq.pop();
for (auto &p : v)
{
p.F--;
if (p.F)
pq.push(p);
}
}
if (pq.empty())
{
cout << ans.size() << '\n';
for (auto v : ans)
{
for (int i : v)
cout << i << ' ';
cout << '\n';
}
}
else
cout << "-1\n";
return 0;
}
// * * ***** * * * * **** **** **** ** **
// * * * ** * * * * * * * * * * *
// ***** ***** * * * * * * **** * * * *
// * * * * ** * * * * * * ***** *
// * * ***** * * *** **** * * **** * *****
// ***** ***** * * * ***** * * ***** *****
// * * * * * * * ** * * * *
// * * * ***** * * * * * * *****
// * * * * * * * * ** * *
// **** ***** * ***** ***** * * * *
Compilation message (stderr)
nicegift.cpp: In function 'int main()':
nicegift.cpp:27:22: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
27 | while (pq.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... |