Advertisement
Josif_tepe

Untitled

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