Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main()
- {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- int n, a, * arr, mem, p, flag;
- cin >> n;
- arr = new int[n];
- for (int j = 0; j < n; j++)
- {
- cin >> a;
- arr[j] = a;
- }
- p = 0;
- mem = 0;
- flag = 0;
- for (int i = 0; i < n; i++)
- {
- if (arr[i + 1] == (arr[i] + 1))
- {
- if (flag == 2)
- p = 0;
- p++;
- if (p > mem)
- mem = p;
- flag = 1;
- }
- else
- {
- if (arr[i + 1] == (arr[i] - 1))
- {
- if (flag == 1)
- p = 0;
- p++;
- if (p > mem)
- mem = p;
- flag = 2;
- }
- else p = 0;
- }
- }
- cout << mem + 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement