Submission #378646

# Submission time Handle Problem Language Result Execution time Memory
378646 2021-03-17T02:40:08 Z daniel920712 Gift (IZhO18_nicegift) C++14
18 / 100
2000 ms 140416 KB
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <stack>
#include <map>
#include <vector>

using namespace std;
map < int , stack < int > > all;
vector < pair < int , int > > que;
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) printf("-1\n");
    else
    {

        while(!all.empty())
        {
            x=all.begin()->second.top();
            a=all.begin()->first;
            all[a].pop();

            if(prev(all.end())->second.empty())
            {
                printf("-1\n");
                return 0;
            }
            y=prev(all.end())->second.top();
            b=prev(all.end())->first;
            all[b].pop();
            //printf("1 %d %d\n",x,y);
            que.push_back(make_pair(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);
        }
        printf("%d\n",ans/K);
        for(auto i:que) printf("1 %d %d\n",i.first,i.second);
    }
    return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:15:15: warning: unused variable 'j' [-Wunused-variable]
   15 |     int N,K,i,j,ans=0,x,y,a,b,t;
      |               ^
nicegift.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |     scanf("%d %d",&N,&K);
      |     ~~~~~^~~~~~~~~~~~~~~
nicegift.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |         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 Correct 4 ms 492 KB n=8
9 Correct 6 ms 620 KB n=14
10 Correct 5 ms 620 KB n=11
11 Correct 22 ms 2028 KB n=50000
12 Correct 22 ms 2028 KB n=50000
13 Correct 20 ms 1224 KB n=10
14 Correct 15 ms 1252 KB n=685
15 Correct 20 ms 1352 KB n=623
16 Correct 11 ms 872 KB n=973
# 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 Correct 4 ms 492 KB n=8
9 Correct 6 ms 620 KB n=14
10 Correct 5 ms 620 KB n=11
11 Correct 22 ms 2028 KB n=50000
12 Correct 22 ms 2028 KB n=50000
13 Correct 20 ms 1224 KB n=10
14 Correct 15 ms 1252 KB n=685
15 Correct 20 ms 1352 KB n=623
16 Correct 11 ms 872 KB n=973
17 Incorrect 18 ms 1380 KB Taken too much stones from the heap
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2067 ms 140416 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 Correct 4 ms 492 KB n=8
9 Correct 6 ms 620 KB n=14
10 Correct 5 ms 620 KB n=11
11 Correct 22 ms 2028 KB n=50000
12 Correct 22 ms 2028 KB n=50000
13 Correct 20 ms 1224 KB n=10
14 Correct 15 ms 1252 KB n=685
15 Correct 20 ms 1352 KB n=623
16 Correct 11 ms 872 KB n=973
17 Incorrect 18 ms 1380 KB Taken too much stones from the heap
18 Halted 0 ms 0 KB -