Advertisement
Goga21

Untitled

Mar 6th, 2025
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int n, cnt = 0, start = 0, end = 0, prev, temp;
  7.     int mx_start, mx_end;
  8.     cin >> n;
  9.     vector<int> v(n);
  10.  
  11.     for (int i = 0; i < n; ++i) {
  12.         cin >> v[i];
  13.     }
  14.     prev = v[0];
  15.     for (int i = 0; i < n; ++i) {
  16.         if (prev == v[i]) {
  17.             ++cnt;
  18.         } else {
  19.             prev = v[i];
  20.             cnt = 1;
  21.             temp = i;
  22.         }
  23.         if (cnt == 3) {
  24.             start = temp + 1;
  25.             cnt = 2;
  26.         }
  27.         ++end;
  28.  
  29.         if (end - start > mx_end - mx_start) {
  30.             mx_end = end;
  31.             mx_start = start;
  32.         }
  33.     }
  34.     cout << mx_start + 1 << ' ' << mx_end;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement