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;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
int main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n,k;cin>>n>>k;
ll asum=0;
vector<int> arr(n);
int maxn = 0;
for(int i=0;i<n;i++){
cin>>arr[i];
asum+=arr[i];
maxn = max(maxn,arr[i]);
}
if(asum%k){
cout<<-1<<"\n";
return 0;
}
if(maxn>asum/k){
cout<<-1<<"\n";
return 0;
}
priority_queue<pair<int,int> > pq;
for(int i=0;i<n;i++){
pq.push({arr[i],i});
}
cout<<asum/k<<"\n";
for(int t=0;t<asum/k;t++){
cout<<1;
vector<int> use;
for(int i=0;i<k;i++){
int p = pq.top().second;
pq.pop();
cout<<" "<<p+1;
arr[p]--;
use.push_back(p);
}
for(auto i : use){
pq.push({arr[i],i});
}
cout<<"\n";
}
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... |