Advertisement
Josif_tepe

Untitled

Mar 6th, 2023
961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n;
  8.     cin >> n;
  9.     vector<int> v(n);
  10.    
  11.     for(int i = 0; i < n; i++) {
  12.         cin >> v[i];
  13.     }
  14.     int i = 0, j = 0;
  15.     int cnt = 0;
  16.     int result = 0;
  17.     while(j < n) {
  18.         if(cnt <= 3) {
  19.             if(v[j] == 3) {
  20.                 cnt++;
  21.             }
  22.             j++;
  23.             if(cnt == 3) {
  24.                 result = max(result, j - i);
  25.             }
  26.         }
  27.         else {
  28.             if(v[i] == 3) {
  29.                 cnt--;
  30.             }
  31.             i++;
  32.            
  33.             if(cnt == 3) {
  34.                 result = max(result, j - i);
  35.             }
  36.         }
  37.     }
  38.     cout << result << endl;
  39.    
  40.     return 0;
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement