Advertisement
StabCrab

СуперКекЧебурек

Mar 1st, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. // вне диапазона из 5 элементов минимальное произведение кратное 3
  2. #include <iostream>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n;
  7.     int min3 = 1001;
  8.     int min = 1001;
  9.     int result = 1000 * 1000 + 1;
  10.     int temp;
  11.     int a[4];
  12.     cin >> n;
  13.     for (int i = 0; i < 4 ; i++)
  14.         cin >> a[i];
  15.     for (int i = 4; i < n; i++)
  16.     {
  17.         cin >> temp;
  18.         if (a[i % 4] % 3 == 0 && a[i % 4] < min3)
  19.             min3 = a[i % 4];
  20.         else
  21.             if (a[i % 4] < min)
  22.                 min = a[i % 4];
  23.         if (temp * min % 3 == 0 && temp * min < result && min != 1001)
  24.             result = temp * min;
  25.         if (temp * min3 < result && min3 != 1001)
  26.             result = temp * min3;
  27.         a[i % 4] = temp;
  28.     }
  29.     if (result == 1000 * 1000 + 1)
  30.         cout << -1;
  31.     else
  32.         cout << result;
  33.     return 0;
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement