# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
334446 | juggernaut | Gift (IZhO18_nicegift) | C++14 | 2054 ms | 11604 KiB |
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 n,k,mx,sum;
priority_queue<pair<int,int>>q;
int main(){
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++){
int x;
scanf("%d",&x);
q.push({x,i});
mx=max(mx,x);
sum+=x;
}
if(sum%k!=0||(mx<<1)>sum)return puts("-1"),0;
vector<vector<int>>ans;
while(!q.empty()){
vector<int>v;
stack<pair<int,int>>temp;
for(int i=0;i<k;i++){
temp.push(q.top());
q.pop();
v.push_back(temp.top().second);
if(temp.top().first<2)temp.pop();
}
while(!temp.empty()){
q.push(temp.top());
temp.pop();
}
}
printf("%d",(int)ans.size());
for(auto v:ans){
printf("\n1");
for(auto to:v)printf("%d ",to);
}
}
Compilation message (stderr)
# | 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... |