Advertisement
Guest User

huilo

a guest
Dec 7th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. void qsort(int *a, int l, int r)
  6. {
  7.     if (r - l <= 1)
  8.         return;
  9.     int m = a[l + rand() % (r - l)];
  10.     int x = l, y = l;
  11.  
  12.     for (int i = l; i < r; i++){
  13.         if (a[i] < m){
  14.             swap(a[x], a[i]);
  15.             if (x != y) swap(a[y], a[i]);
  16.             x++;
  17.             y++;
  18.         }else if (a[i] == m){
  19.             swap(a[y], a[i]);
  20.             y++;
  21.         }
  22.     }
  23.  
  24.     qsort(a, l, x);
  25.     qsort(a, y, r);
  26. }
  27.  
  28. int main()
  29. {
  30.     int n;
  31.     cin >> n;
  32.  
  33.     int a[100000];
  34.     for (int i = 0; i < n; i++)
  35.         cin >> a[i];
  36.  
  37.     qsort(a, 0, n);
  38.  
  39.     if (a[0] * a[1] * a[n-1] >= a[n-3] * a[n-2] * a[n-1])
  40.         cout << a[0] << ' ' << a[1] << ' ' << a[n - 1] << endl;
  41.     else
  42.         cout << a[n - 3] << ' ' << a[n - 2] << ' ' << a[n - 1] << endl;
  43.  
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement