Advertisement
Guest User

Untitled

a guest
Feb 11th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6.     long n, x, pos_min_1 = -1, pos_min_2 = -1, pos_max = -1, neg_max = 1, neg_max_1 = 1, neg_max_2 = 1;
  7.     cin >> n;
  8.     for (long i = 0; i < n; ++i){
  9.         cin >> x;
  10.         if ((x < pos_min_1 || pos_min_1 == -1) && x >= 0) {pos_min_2 = pos_min_1; pos_min_1 = x;}
  11.         else if ((x < pos_min_2 || pos_min_2 == -1) && x >= 0) pos_min_2 = x;
  12.         if (x > pos_max && x > 0) pos_max = x;
  13.         else if (x < neg_max && x < 0) neg_max = x;
  14.         if (x <= 0 && (x > neg_max_1 || neg_max_1 == 1)) {neg_max_2 = neg_max_1; neg_max_1 = x;}
  15.         else if(x <= 0 && (x > neg_max_2 || neg_max_2 == 1)) neg_max_2 = x;
  16.     }
  17.     if (pos_min_2 >= 0 && pos_max > 0 && neg_max < 0 && neg_max_2 <= 0)
  18.         cout << min(pos_min_1 * pos_min_2, min(pos_max * neg_max, neg_max_1 * neg_max_2)) << endl;
  19.     else if (pos_min_2 >= 0 && pos_max > 0 && neg_max < 0) cout << min(pos_min_1 * pos_min_2, pos_max * neg_max) << endl;
  20.     else if (pos_max > 0 && neg_max < 0 && neg_max_2 <= 0) cout << min(pos_max * neg_max, neg_max_1 * neg_max_2) << endl;
  21.     else if (pos_min_2 >= 0 && neg_max_2 <= 0) cout << min(pos_min_1 * pos_min_2, neg_max_1 * neg_max_2) << endl;
  22.     else if (pos_min_2 >= 0) cout << pos_min_1 * pos_min_2 << endl;
  23.     else if (pos_max > 0 && neg_max < 0) cout << pos_max * neg_max;
  24.     else cout << neg_max_1 * neg_max_2;
  25.     return 0;
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement