# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
378611 | daniel920712 | Gift (IZhO18_nicegift) | C++14 | 2094 ms | 96152 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 <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <stack>
#include <map>
using namespace std;
map < int , stack < int > > all;
int tt[1000005];
int main()
{
//freopen("aa.txt","w+t",stdout);
int N,K,i,j,ans=0,x,y,a,b,t;
scanf("%d %d",&N,&K);
for(i=1;i<=N;i++)
{
scanf("%d",&t);
all[t].push(i);
ans+=t;
tt[i]=t;
}
if(ans%K||N==2&&tt[1]!=tt[2]) printf("-1\n");
else
{
//printf("%d\n",ans/K);
while(!all.empty())
{
x=all.begin()->second.top();
a=all.begin()->first;
all[a].pop();
//if(prev(all.end())->second.empty()) while(1);
y=prev(all.end())->second.top();
b=prev(all.end())->first;
all[b].pop();
printf("1 %d %d\n",x,y);
if(all[a].empty()) all.erase(a);
if(a!=b&&all[b].empty()) all.erase(b);
if(a!=1) all[a-1].push(x);
if(b!=1) all[b-1].push(y);
}
}
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... |