Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int main()
- {
- int n;
- cin >> n;
- vector<int> v(n);
- for(int i = 0; i < n; i++) {
- cin >> v[i];
- }
- int i = 0, j = 0;
- int cnt = 0;
- int result = 0;
- while(j < n) {
- if(cnt <= 3) {
- if(v[j] == 3) {
- cnt++;
- }
- j++;
- if(cnt == 3) {
- result = max(result, j - i);
- }
- }
- else {
- if(v[i] == 3) {
- cnt--;
- }
- i++;
- if(cnt == 3) {
- result = max(result, j - i);
- }
- }
- }
- cout << result << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement