Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <algorithm>
- using namespace std;
- int main()
- {
- long long a=0, n=0, z=0, max=0, min=0;
- cin >> a;
- int arr[a];
- for (int i=0; i<a; i++)
- cin >> arr[i];
- for (int i=0; i<a-1; ++i)
- {
- if (abs(arr[i+1])-abs(arr[i])==1)
- {
- if (arr[i+1]<0 && arr[i]<0)
- n++;
- else if (arr[i+1]>0 && arr[i]>0)
- z++;
- else
- {
- n=0;
- z=0;
- }
- if (max < z)
- max = z;
- if (min < n)
- min = n;
- }
- else
- {
- z=0;
- n=0;
- }
- }
- if (max!=0)
- cout << max+1;
- else if(min!=0)
- cout << min +1;
- else cout << 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement