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;
#define sz(s) (int)s.size()
#define ff first
#define ss second
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, k;
cin >> n >> k;
vector <int> a(n);
multiset <pair<int,int>> s;
for(int i = 0; i < n; i++){
cin >> a[i];
if(a[i] == 0) continue;
s.insert({a[i],i+1});
}
vector <pair<int,int>> v1;
vector <int> v;
while(sz(s) >= k){
v1.clear();
for(int i = 0; i < k; i++){
v1.push_back(*(--s.end()));
s.erase(--s.end());
}
for(int i = 0; i < k; i++){
v1.back().ff--;
if(v1.back().ff != 0) s.insert(v1.back());
v.push_back(v1.back().ss);
v1.pop_back();
}
}
if(sz(s) > 0){
cout << -1;
return 0;
}
reverse(v.begin(), v.end());
cout << sz(v)/k << "\n";
int x = sz(v)/k;
while(x--){
cout << 1 << " ";
int cnt = k;
while(cnt--){
cout << v.back() << ' ';
v.pop_back();
}
cout << '\n';
}
}
# | 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... |