Submission #340518

# Submission time Handle Problem Language Result Execution time Memory
340518 2020-12-27T19:45:26 Z scales Gift (IZhO18_nicegift) C++17
0 / 100
2000 ms 43704 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 Incorrect 1 ms 364 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2062 ms 43704 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -