# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
48535 | Pajaraja | Gift (IZhO18_nicegift) | C++17 | 2059 ms | 22732 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 gcd(int a,int b)
{
if(a==0) return b;
return gcd(b%a,a);
}
int main()
{
int n,k,t,cnt=0;
long long sum=0;
scanf("%d%d",&n,&k);
priority_queue<pair<int,int> > pq,pq1;
for(int i=0;i<n;i++) {scanf("%d",&t); pq.push(make_pair(t,i+1)); pq1.push(make_pair(t,i+1)); sum+=t;}
if(sum>100000)
{
while(pq.size()>=k)
{
stack<pair<int,int> > st;
for(int i=0;i<k;i++) {st.push(pq.top()); pq.pop();}
int f=st.top().first;
if(!pq.empty()) f-=pq.top().first-1;
for(int i=0;i<k;i++) {st.top().first--; if(st.top().first!=0) pq.push(st.top()); st.pop();}
cnt++;
}
if(!pq.empty()) {printf("-1"); return 0;}
printf("%d\n",cnt);
while(pq1.size()>=k)
{
stack<pair<int,int> > st;
for(int i=0;i<k;i++) {st.push(pq1.top()); pq1.pop();}
for(int i=0;i<k;i++) {st.top().first--; if(st.top().first!=0) pq1.push(st.top()); printf("%d ",st.top().second); st.pop();}
printf("\n");
}
}
else
{
int f=k/(gcd(n,k));
while(pq.size()>=k)
{
stack<pair<int,int> > st;
for(int i=0;i<k;i++) {st.push(pq.top()); pq.pop();}
for(int i=0;i<k;i++) {st.top().first-=f; if(st.top().first!=0) pq.push(st.top()); st.pop();}
cnt++;
}
if(!pq.empty()) {printf("-1"); return 0;}
printf("%d\n",cnt);
while(pq1.size()>=k)
{
stack<pair<int,int> > st;
for(int i=0;i<k;i++) {st.push(pq1.top()); pq1.pop();}
printf("%d ",f);
for(int i=0;i<k;i++) {st.top().first-=f; if(st.top().first!=0) pq1.push(st.top()); printf("%d ",st.top().second); st.pop();}
printf("\n");
}
}
}
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... |