Submission #340519

# Submission time Handle Problem Language Result Execution time Memory
340519 2020-12-27T19:46:25 Z scales Gift (IZhO18_nicegift) C++17
18 / 100
2000 ms 28780 KB
#include <bits/stdc++.h>
/*#ifndef LOCAL_RUN
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    #pragma GCC optimize("fast-math")
    #pragma GCC target("avx2,tune=native")
#endif*/
using namespace std;
int main()
{
      ios::sync_with_stdio(false);
      cin.tie(0);
     // freopen("input.txt","r",stdin);
     // freopen("output.txt","w",stdout);
     long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v,f,s,h,z1,rov;
     cin>>n;
     cin>>k;
     vector<pair<long long,long long> > a(n);
     sum=0;
     for(i=0;i<n;i++)
     {
         cin>>a[i].first;
         sum=sum+a[i].first;
         a[i].second=i+1;
     }
     sort(a.begin(),a.end());
     /*for(i=0;i<n;i++)
     {
         cout<<a[i].first<<" "<<a[i].second<<endl;
     }*/
     if( ((sum%k)!=0) || a[n-1].first>(sum/k))
     {
         cout<<-1<<endl;
     }
     else
     {
         cout<<sum/2<<endl;
         sum=sum/k;
         l=n-1;
         //cout<<"sum="<<sum<<endl;
         while(sum>0)
         {
             sum=sum-a[l].first;
             //cout<<"sum="<<sum<<endl;
             l--;
         }
         l++;
         //cout<<"sum="<<sum<<endl;
         while(sum<0)
         {
             cout<<1<<" "<<a[n-1].second<<" "<<a[l].second<<endl;
             a[n-1].first--;
             a[l].first--;
             sum++;
         }
         r=l;
         l--;
         while(l!=-1)
         {
             cout<<1<<" "<<a[r].second<<" "<<a[l].second<<endl;
             a[l].first--;
             a[r].first--;
             if(a[l].first==0)
             {
                 l--;
             }
             if(a[r].first==0)
             {
                 r++;
             }
         }
     }

    return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:15:16: warning: unused variable 't' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v,f,s,h,z1,rov;
      |                ^
nicegift.cpp:15:20: warning: unused variable 'j' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v,f,s,h,z1,rov;
      |                    ^
nicegift.cpp:15:22: warning: unused variable 'dno' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v,f,s,h,z1,rov;
      |                      ^~~
nicegift.cpp:15:26: warning: unused variable 'x' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v,f,s,h,z1,rov;
      |                          ^
nicegift.cpp:15:28: warning: unused variable 'y' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v,f,s,h,z1,rov;
      |                            ^
nicegift.cpp:15:30: warning: unused variable 'z' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v,f,s,h,z1,rov;
      |                              ^
nicegift.cpp:15:32: warning: unused variable 'w' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v,f,s,h,z1,rov;
      |                                ^
nicegift.cpp:15:34: warning: unused variable 'm' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v,f,s,h,z1,rov;
      |                                  ^
nicegift.cpp:15:40: warning: unused variable 'x1' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v,f,s,h,z1,rov;
      |                                        ^~
nicegift.cpp:15:43: warning: unused variable 'y1' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v,f,s,h,z1,rov;
      |                                           ^~
nicegift.cpp:15:46: warning: unused variable 'tip' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v,f,s,h,z1,rov;
      |                                              ^~~
nicegift.cpp:15:50: warning: unused variable 'p' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v,f,s,h,z1,rov;
      |                                                  ^
nicegift.cpp:15:60: warning: unused variable 'maxi' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v,f,s,h,z1,rov;
      |                                                            ^~~~
nicegift.cpp:15:65: warning: unused variable 'kol' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v,f,s,h,z1,rov;
      |                                                                 ^~~
nicegift.cpp:15:69: warning: unused variable 'v' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v,f,s,h,z1,rov;
      |                                                                     ^
nicegift.cpp:15:71: warning: unused variable 'f' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v,f,s,h,z1,rov;
      |                                                                       ^
nicegift.cpp:15:73: warning: unused variable 's' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v,f,s,h,z1,rov;
      |                                                                         ^
nicegift.cpp:15:75: warning: unused variable 'h' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v,f,s,h,z1,rov;
      |                                                                           ^
nicegift.cpp:15:77: warning: unused variable 'z1' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v,f,s,h,z1,rov;
      |                                                                             ^~
nicegift.cpp:15:80: warning: unused variable 'rov' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v,f,s,h,z1,rov;
      |                                                                                ^~~
# 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 1 ms 364 KB n=8
9 Correct 36 ms 492 KB n=14
10 Correct 20 ms 364 KB n=11
11 Correct 125 ms 1900 KB n=50000
12 Correct 125 ms 1900 KB n=50000
13 Correct 119 ms 620 KB n=10
14 Correct 101 ms 748 KB n=685
15 Correct 109 ms 876 KB n=623
16 Correct 61 ms 620 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 1 ms 364 KB n=8
9 Correct 36 ms 492 KB n=14
10 Correct 20 ms 364 KB n=11
11 Correct 125 ms 1900 KB n=50000
12 Correct 125 ms 1900 KB n=50000
13 Correct 119 ms 620 KB n=10
14 Correct 101 ms 748 KB n=685
15 Correct 109 ms 876 KB n=623
16 Correct 61 ms 620 KB n=973
17 Incorrect 155 ms 1216 KB Taken too much stones from the heap
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2023 ms 28780 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 1 ms 364 KB n=8
9 Correct 36 ms 492 KB n=14
10 Correct 20 ms 364 KB n=11
11 Correct 125 ms 1900 KB n=50000
12 Correct 125 ms 1900 KB n=50000
13 Correct 119 ms 620 KB n=10
14 Correct 101 ms 748 KB n=685
15 Correct 109 ms 876 KB n=623
16 Correct 61 ms 620 KB n=973
17 Incorrect 155 ms 1216 KB Taken too much stones from the heap
18 Halted 0 ms 0 KB -