This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//-------------dilanyan------------\\
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
//------------------KarginDefines--------------------\\
#define ll long long
#define pb push_back
#define all(u) (u).begin(), (u).end()
#define pqueue priority_queue
#define upper upper_bound
#define lower lower_bound
#define umap unordered_map
#define uset unordered_set
#define Kargin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Usaco freopen(".in", "r", stdin); freopen(".out", "w", stdout);
//-------------------KarginConstants------------------\\
const ll mod = 1000000007;
const ll inf = 1e9 + 15;
//-------------------KarginCode------------------------\\
const int N = 100005;
int a[N];
void KarginSolve() {
int n, k;
cin >> n >> k;
int sum = 0;
for (int i = 1; i <= n;i++) cin >> a[i], sum += a[i];
if (sum % k) {
cout << "-1\n";
return;
}
pqueue<pair<int, int>> pq;
for (int i = 1;i <= n;i++) pq.push({ a[i],i });
cout << sum / k << '\n';
for (int j = 0; j < sum / k;j++) {
cout << 1 << ' ';
for (int i = 0; i < k;i++) {
int ind = pq.top().second; pq.pop();
a[ind]--;
cout << ind << ' ';
}
while (!pq.empty()) pq.pop();
for (int i = 1;i <= n;i++) {
if (a[i]) pq.push({ a[i],i });
}
cout << '\n';
}
}
int main() {
//Usaco
Kargin;
int test = 1;
//cin >> test;
while (test--) {
KarginSolve();
}
return 0;
}
Compilation message (stderr)
nicegift.cpp:1:1: warning: multi-line comment [-Wcomment]
1 | //-------------dilanyan------------\\
| ^
nicegift.cpp:8:1: warning: multi-line comment [-Wcomment]
8 | //------------------KarginDefines--------------------\\
| ^
nicegift.cpp:22:1: warning: multi-line comment [-Wcomment]
22 | //-------------------KarginConstants------------------\\
| ^
nicegift.cpp:27:1: warning: multi-line comment [-Wcomment]
27 | //-------------------KarginCode------------------------\\
| ^
# | 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... |