Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <vector>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- 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_3 = 0, res = 0;
- while(j < n) {
- if(cnt_3 <= 3) {
- if(v[j] == 3) {
- cnt_3++;
- }
- j++;
- if(cnt_3 == 3) {
- res = max(res, j - i);
- }
- }
- else {
- if(v[i] == 3) {
- cnt_3--;
- }
- i++;
- if(cnt_3 == 3) {
- res = max(res, j - i);
- }
- }
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement