Created
October 14, 2017 08:07
-
-
Save henrybear327/6c94251ca4e48f4745d763c3f72fb9c4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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