Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main(){
- 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;
- cin >> n;
- for (long i = 0; i < n; ++i){
- cin >> x;
- if ((x < pos_min_1 || pos_min_1 == -1) && x >= 0) {pos_min_2 = pos_min_1; pos_min_1 = x;}
- else if ((x < pos_min_2 || pos_min_2 == -1) && x >= 0) pos_min_2 = x;
- if (x > pos_max && x > 0) pos_max = x;
- else if (x < neg_max && x < 0) neg_max = x;
- if (x <= 0 && (x > neg_max_1 || neg_max_1 == 1)) {neg_max_2 = neg_max_1; neg_max_1 = x;}
- else if(x <= 0 && (x > neg_max_2 || neg_max_2 == 1)) neg_max_2 = x;
- }
- if (pos_min_2 >= 0 && pos_max > 0 && neg_max < 0 && neg_max_2 <= 0)
- cout << min(pos_min_1 * pos_min_2, min(pos_max * neg_max, neg_max_1 * neg_max_2)) << endl;
- 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;
- 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;
- 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;
- else if (pos_min_2 >= 0) cout << pos_min_1 * pos_min_2 << endl;
- else if (pos_max > 0 && neg_max < 0) cout << pos_max * neg_max;
- else cout << neg_max_1 * neg_max_2;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement