Advertisement
StabCrab

Untitled

Jun 12th, 2019
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.12 KB | None | 0 0
  1. #include <cmath>
  2. #include <iostream>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n, max3 = -1, min3 = INT_MAX, max2 = -1, min2= INT_MAX, max1 = -1, min1 = INT_MAX, res = -10;
  7.     cin >> n;
  8.     int a[5];
  9.     for (int i = 0; i < 5; i++)
  10.     {
  11.         cin >> a[i];
  12.     }
  13.     int temp;
  14.     for (int i = 5; i < n; i++)
  15.     {
  16.         switch (a[i - 5] % 3)
  17.         {
  18.             case 0:
  19.             {
  20.                 if (a[i - 5] > max3)
  21.                     max3 = a[i - 5];
  22.                 if (a[i - 5] < min3)
  23.                     min3 = a[i - 5];
  24.                 break;
  25.             }
  26.             case 1:
  27.             {
  28.                 if (a[i - 5] > max1)
  29.                     max1 = a[i - 5];
  30.                 if (a[i - 5] < min1)
  31.                     min1 = a[i - 5];
  32.                 break;
  33.             }
  34.             case 2:
  35.             {
  36.                 if (a[i - 5] > max2)
  37.                     max2 = a[i - 5];
  38.                 if (a[i - 5] < min2)
  39.                     min2 = a[i - 5];
  40.                 break;
  41.             }
  42.             default:break;
  43.         }
  44.         cin >> temp;
  45.         switch (temp % 3)
  46.         {
  47.             case 0:
  48.             {
  49.                 if (abs(temp - min3) > res && min3 != INT_MAX)
  50.                     res = abs(temp - min3);
  51.                 if (abs(max3 - temp) > res && max3 != -1)
  52.                     res = abs(max3 - temp);
  53.                 break;
  54.             }
  55.             case 1:
  56.             {
  57.                 if (abs(temp - min1) > res && min1 != INT_MAX)
  58.                     res = abs(temp - min1);
  59.                 if (abs(max1 - temp) > res && max1 != -1)
  60.                     res = abs(max1 - temp);
  61.                 break;
  62.             }
  63.             case 2:
  64.             {
  65.                 if (abs(temp - min2) > res && min2 != INT_MAX)
  66.                     res = abs(temp - min2);
  67.                 if (abs(max2 - temp) > res && max2 != -1)
  68.                     res = abs(max2 - temp);
  69.                 break;
  70.             }
  71.             default:break;
  72.         }
  73.         a[i - 5] = temp;
  74.     }
  75.     if (res == -10)
  76.         cout << "NO";
  77.     else
  78.         cout << res;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement