Advertisement
Patrickmeme

Butoi

Mar 12th, 2023
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.91 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3.  
  4. ifstream cin("butoi.in");
  5. ofstream cout("butoi.out");
  6. int v[10],gal[10],aux[10];
  7. long long vd[100000];
  8. int main()
  9. {
  10.     int cer,nrg,maxop,p,rasp,min1,cnt,s,j,stg;
  11.     long long cb,put,i,cntd;
  12.     cin>>cer;
  13.     cin>>cb>>nrg>>maxop>>p;
  14.     min1=99999999;
  15.     if(cer<3){
  16.         for(i=0;i<nrg;i++){
  17.             cin>>gal[i];
  18.         }
  19.         cntd=s=0;
  20.         put=1;
  21.         for(i=0;i<=nrg+10;i++){
  22.             put*=maxop;
  23.         }
  24.         for(i=0;i<put;i++){
  25.             v[0]++;
  26.             j=0;
  27.             while(j<nrg-1 && v[j]==maxop+1 ){
  28.                 v[j]=0;
  29.                 v[j+1]++;
  30.                 j++;
  31.             }
  32.             cnt=s=stg=0;
  33.             for(j=0;j<nrg;j++){
  34.                 if(v[j]!=maxop)
  35.                     stg=1;
  36.                 s+=v[j]*gal[j];
  37.                 cnt+=v[j];
  38.             }
  39.             if(s==cb){
  40.                 cntd++;
  41.                 if(cnt<min1){
  42.                     min1=cnt;
  43.                     for(j=0;j<nrg;j++)
  44.                         aux[j]=v[j];
  45.                 }
  46.             }
  47.             if(stg==0)
  48.                 break;
  49.         }
  50.         if(cer==1){
  51.             cout<<cntd;
  52.         }else{
  53.             for(j=0;j<nrg;j++)
  54.                 cout<<aux[j]<<" ";
  55.         }
  56.  
  57.     }else{
  58.         cin>>vd[0];
  59.         for(i=1;i<nrg;i++){
  60.             cin>>vd[i];
  61.             vd[i]+=vd[i-1];
  62.         }
  63.         i=0;
  64.         rasp=-1;
  65.         while(i<nrg-p+1){
  66.             if(i==0){
  67.                 if(cb%vd[p-1]==0 && cb/vd[p-1]<min1){
  68.                     rasp=i+1;
  69.                     min1=cb/vd[p-1];
  70.                 }
  71.  
  72.             }else{
  73.                 if(cb%(vd[i+p-1]-vd[i-1])==0 && cb/(vd[i+p-1]-vd[i-1])<min1){
  74.                     rasp=i+1;
  75.                     min1=cb/(vd[i+p-1]-vd[i-1]);
  76.                 }
  77.             }
  78.             i++;
  79.         }
  80.         cout<<rasp;
  81.     }
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement