Advertisement
hung_mine

MINPRODUCT

Oct 13th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. /// from HUNG MINE with love <3
  4. int n, a[1000001];
  5. void inline read (int &x) {
  6.       int flag = 1;
  7.       x = 0;
  8.       char c = getchar ();//cout << c << "\n";
  9.       while (c < '0' || c > '9') {
  10.             if (c == '-') {
  11.                   flag = -1;
  12.             }
  13.             c = getchar ();
  14.       }
  15.       while (c >= '0' && c <= '9') {
  16.             x = x * 10 + (c - '0');
  17.             c = getchar ();
  18.       }
  19.       x *= flag;//cerr << x;
  20.  
  21. }
  22. int main () {
  23. //      if (fopen ("test.inp", "r")) {
  24. //            freopen ("test.inp", "r", stdin);
  25. //      }
  26.       {
  27.             freopen ("MINPRODUCT.inp", "r", stdin);
  28.             freopen ("MINPRODUCT.out", "w", stdout);
  29.       }
  30.  
  31.       ios_base :: sync_with_stdio (0);
  32.       cin.tie (0);
  33.       cout.tie (0);
  34.       read (n);//cerr << n;
  35.       for (int i = 1; i <= n; ++ i) {
  36.             read (a[i]);
  37.       }
  38.       sort (a + 1, a + n + 1);
  39.       if (a[1] < 0 && a[n] > 0) return cout << a[1] * a[n], 0;
  40.       if (a[n] <= 0) return cout << a[n - 1] * a[n], 0;
  41.       if (a[1] >= 0) return cout << a[1] * a[2], 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement