Advertisement
Guest User

ciuperci

a guest
Dec 6th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin("ciuperci.in");
  6.  
  7. struct ciuperci
  8. {
  9.     int g;
  10.     bool ot;
  11. }v[5000];
  12.  
  13. void Read(int &n, int &L)
  14. {
  15.     fin>>n>>L;
  16.     for(int i=1; i<=n; i++)
  17.     {
  18.         fin>>v[i].g;
  19.         fin>>v[i].ot;
  20.     }
  21. //    for(int i=1; i<=n; i++)
  22. //        cout<<v[i].g<<"   "<<v[i].ot<<endl;
  23. }
  24.  
  25. int DetMax(int k, int L, int &maxx, int n, int &mod)
  26. {
  27.     if(v[k].ot==1)
  28.         return 0;
  29.  
  30.     int p=k+1, cnt=1, l;
  31.     cout<<cnt<<" -- "<<maxx<<" -- "<<mod<<endl;
  32.     while(p<=n)
  33.     {
  34.         l=p-k;
  35.         if(v[k].ot==0)
  36.             if(v[k].g < v[p].g && v[p].ot==0 && l <= L)
  37.             {
  38.                 cnt++;
  39.                 cout<<" |----> "<<v[k].g<<" -- "<<v[p].g<<endl;
  40.                 k=p;
  41.                 p++;
  42.             }
  43.             else
  44.                 p++;
  45.         else
  46.         {
  47.             k++;
  48.             p++;
  49.         }
  50.     }
  51.     if(cnt > maxx)
  52.     {
  53.         maxx = cnt;
  54.         mod = 0;
  55.     }
  56.     if(cnt == maxx)
  57.         mod++;
  58.     cout<<cnt<<" -- "<<maxx<<" -- "<<mod<<endl<<endl<<endl;
  59. }
  60.  
  61. int main()
  62. {
  63.     clock_t tStart = clock();
  64.     int n, L;
  65.     Read(n,L);
  66.     int maxx=0, mod=0;
  67.     for(int i=1; i<n; i++)
  68.         DetMax(i,L,maxx,n, mod);
  69.     if(maxx==0 && mod==0)
  70.         cout<<"nu exista"<<endl;
  71.     else
  72.         cout<<maxx<<" "<<mod<<endl;
  73.     cout<<"Timp: "<<(float)(clock()-tStart)/CLOCKS_PER_SEC<<endl;
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement