Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- void qsort(int *a, int l, int r)
- {
- if (r - l <= 1)
- return;
- int m = a[l + rand() % (r - l)];
- int x = l, y = l;
- for (int i = l; i < r; i++){
- if (a[i] < m){
- swap(a[x], a[i]);
- if (x != y) swap(a[y], a[i]);
- x++;
- y++;
- }else if (a[i] == m){
- swap(a[y], a[i]);
- y++;
- }
- }
- qsort(a, l, x);
- qsort(a, y, r);
- }
- int main()
- {
- int n;
- cin >> n;
- int a[100000];
- for (int i = 0; i < n; i++)
- cin >> a[i];
- qsort(a, 0, n);
- if (a[0] * a[1] * a[n-1] >= a[n-3] * a[n-2] * a[n-1])
- cout << a[0] << ' ' << a[1] << ' ' << a[n - 1] << endl;
- else
- cout << a[n - 3] << ' ' << a[n - 2] << ' ' << a[n - 1] << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement