Josif_tepe

Untitled

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