Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <iostream>
- using namespace std;
- int main()
- {
- int n, max3 = -1, min3 = INT_MAX, max2 = -1, min2= INT_MAX, max1 = -1, min1 = INT_MAX, res = -10;
- cin >> n;
- int a[5];
- for (int i = 0; i < 5; i++)
- {
- cin >> a[i];
- }
- int temp;
- for (int i = 5; i < n; i++)
- {
- switch (a[i - 5] % 3)
- {
- case 0:
- {
- if (a[i - 5] > max3)
- max3 = a[i - 5];
- if (a[i - 5] < min3)
- min3 = a[i - 5];
- break;
- }
- case 1:
- {
- if (a[i - 5] > max1)
- max1 = a[i - 5];
- if (a[i - 5] < min1)
- min1 = a[i - 5];
- break;
- }
- case 2:
- {
- if (a[i - 5] > max2)
- max2 = a[i - 5];
- if (a[i - 5] < min2)
- min2 = a[i - 5];
- break;
- }
- default:break;
- }
- cin >> temp;
- switch (temp % 3)
- {
- case 0:
- {
- if (abs(temp - min3) > res && min3 != INT_MAX)
- res = abs(temp - min3);
- if (abs(max3 - temp) > res && max3 != -1)
- res = abs(max3 - temp);
- break;
- }
- case 1:
- {
- if (abs(temp - min1) > res && min1 != INT_MAX)
- res = abs(temp - min1);
- if (abs(max1 - temp) > res && max1 != -1)
- res = abs(max1 - temp);
- break;
- }
- case 2:
- {
- if (abs(temp - min2) > res && min2 != INT_MAX)
- res = abs(temp - min2);
- if (abs(max2 - temp) > res && max2 != -1)
- res = abs(max2 - temp);
- break;
- }
- default:break;
- }
- a[i - 5] = temp;
- }
- if (res == -10)
- cout << "NO";
- else
- cout << res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement