Skip to content

Instantly share code, notes, and snippets.

@henrybear327
Created October 14, 2017 08:07
Show Gist options
  • Save henrybear327/6c94251ca4e48f4745d763c3f72fb9c4 to your computer and use it in GitHub Desktop.
Save henrybear327/6c94251ca4e48f4745d763c3f72fb9c4 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve()
{
int n;
scanf("%d", &n);
int inp[n];
for(int i = 0; i < n; i++) {
scanf("%d", &inp[i]);
}
sort(inp, inp + n);
// implement
// -------++++++++
ll product = inp[0] * inp[1];
ll ans = LLONG_MIN;
for(int i = 2; i < n; i++) {
ans = max(ans, product * inp[i]);
}
product = inp[n - 1] * inp[n - 2];
for(int i = 0; i < n - 2; i++) {
ans = max(ans, product * inp[i]);
}
printf("%lld\n", ans);
}
int main()
{
int ncase;
scanf("%d", &ncase);
while(ncase--)
solve();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment