Submission #378603

# Submission time Handle Problem Language Result Execution time Memory
378603 2021-03-17T02:09:49 Z daniel920712 Gift (IZhO18_nicegift) C++14
7 / 100
2000 ms 86120 KB
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <stack>
#include <map>

using namespace std;
map < int , stack < int > > all;
int main()
{
    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;
    }
    if(ans%K) printf("-1\n");
    else
    {
        printf("%d\n",ans/K);
        while(!all.empty())
        {
            x=all.begin()->second.top();
            a=all.begin()->first;
            all[a].pop();

            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

nicegift.cpp: In function 'int main()':
nicegift.cpp:11:15: warning: unused variable 'j' [-Wunused-variable]
   11 |     int N,K,i,j,ans=0,x,y,a,b,t;
      |               ^
nicegift.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 |     scanf("%d %d",&N,&K);
      |     ~~~~~^~~~~~~~~~~~~~~
nicegift.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 |         scanf("%d",&t);
      |         ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Runtime error 6 ms 492 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Runtime error 6 ms 492 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2075 ms 86120 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Runtime error 6 ms 492 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -