-
Notifications
You must be signed in to change notification settings - Fork 0
/
B.cpp
51 lines (45 loc) · 1.21 KB
/
B.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Problem : B. Maximum Product
// Contest : Codeforces - Codeforces Round #670 (Div. 2)
// URL : https://codeforces.com/contest/1406/problem/B
// Memory Limit : 512 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
const int MAX = 100007;
const int MOD = 1000000007;
void solve() {
int n;
cin >> n;
long long a[MAX];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
cout << max(a[0] * a[1] * a[2] * a[3] * a[4], max(a[0] * a[1] * a[2] * a[3] * a[n - 1], max(a[0] * a[1] * a[n - 1] * a[n - 2] * a[n - 3], a[n - 1] * a[n - 2] * a[n - 3] * a[n - 4] * a[n - 5]))) << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
//freopen("in.in", "r", stdin); freopen("out.out", "w", stdout);
int tt; cin >> tt; for (int i = 1; i <= tt; i++) {solve();}
//solve();
}