Advertisement
Josif_tepe

Untitled

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