# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
76850 | zetapi | Gift (IZhO18_nicegift) | C++14 | 2049 ms | 104296 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;
#define pb push_back
#define mp make_pair
#define int long long
#define itr iterator
typedef pair<int,int> pii;
const int MAX=5e6;
set<pii> st;
set<pii>::itr it_1,it_2;
vector<int> res;
int N,K,sum,arr[MAX];
void print_1()
{
assert(!(st.size()%K));
while(!st.empty())
{
res.pb(st.begin()->second);
st.erase(st.begin());
}
cout<<res.size()/K<<"\n";
for(int A=0;A<res.size();A+=K)
{
cout<<1<<" ";
for(int B=A;B<A+K;B++)
cout<<res[B]<<" ";
cout<<"\n";
}
return ;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin>>N>>K;
for(int A=1;A<=N;A++)
{
cin>>arr[A];
sum+=arr[A];
if(arr[A])
st.insert(mp(-arr[A],A));
}
if(sum%K)
return cout<<-1,0;
vector<pii> lol(K);
while(true)
{
if(st.size()<K)
return cout<<-1,0;
if(st.begin()->first==-1)
{
print_1();
break;
}
for(int A=0;A<K;A++)
{
lol[A]=*st.begin();
st.erase(st.begin());
}
for(int A=0;A<K;A++)
{
lol[A].first++;
if(lol[A].first!=0)
st.insert(lol[A]);
res.pb(lol[A].second);
}
/*for(auto A:st)
cout<<-A.first<<" ";
cout<<"\n";*/
}
return 0;
}
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... |