Advertisement
rotti321

[optimizat] Cea mai lunga secv para din sir [cea mai din drp]]

Mar 21st, 2022
971
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     ifstream cin("test.in");
  7. //  ofstream cout("test.out");
  8.  
  9.     int n,m,x,y,lung=1,lmax=0,pozST,pozDR;
  10.     cin>>n>>x;
  11.  
  12.     for (int i=2; i<=n; i++)
  13.     {
  14.         cin>>y;
  15.         if (x%2==0 && y%2==0)
  16.         {
  17.             lung++;
  18.         }
  19.         else
  20.         {
  21.             lung=1;
  22.         }
  23.         if (lung>=lmax)
  24.         {
  25.             lmax=lung;///lung = pozDR - pozST +1
  26.             pozDR = i;
  27.             pozST = pozDR - lung +1;
  28.         }
  29.         x=y;
  30.     }
  31.     cout<<lmax<<" "<<pozST<<" "<<pozDR;
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement