aboutsummaryrefslogtreecommitdiff
path: root/codechef
diff options
context:
space:
mode:
Diffstat (limited to 'codechef')
-rwxr-xr-xcodechef/sticks/mainbin0 -> 85968 bytes
-rw-r--r--codechef/sticks/main.cpp42
-rw-r--r--codechef/sticks/main_input0.txt5
-rw-r--r--codechef/sticks/main_input1.txt7
-rw-r--r--codechef/sticks/main_output0.txt2
-rw-r--r--codechef/sticks/main_output1.txt3
6 files changed, 59 insertions, 0 deletions
diff --git a/codechef/sticks/main b/codechef/sticks/main
new file mode 100755
index 0000000..ebd7c57
--- /dev/null
+++ b/codechef/sticks/main
Binary files differ
diff --git a/codechef/sticks/main.cpp b/codechef/sticks/main.cpp
new file mode 100644
index 0000000..b5fae0e
--- /dev/null
+++ b/codechef/sticks/main.cpp
@@ -0,0 +1,42 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+ int tt;
+ cin >> tt;
+ while (tt--) {
+ int n;
+ cin >> n;
+ vector<int> v(n);
+ map<int, int> mp;
+ for (int &x : v) {
+ cin >> x;
+ mp[x]++;
+ }
+ vector<int> pair;
+ set<int> vis;
+ int sq = 0;
+ sort(v.begin(), v.end());
+ for(int i = v.size() - 1; i > 0; i--) {
+ int elem = v[i];
+ if(mp[elem] >= 4) {
+ sq = elem;
+ }
+ if(mp[elem] >= 2 && !vis.count(elem)) {
+ if(pair.size() == 2) {
+ break;
+ }
+ pair.push_back(elem);
+ vis.insert(elem);
+ }
+ }
+ if(pair.size() == 2) {
+ cout << max(pair[0] * pair[1], sq * sq) << endl;
+ } else {
+ cout << -1 << endl;
+ }
+ }
+}
diff --git a/codechef/sticks/main_input0.txt b/codechef/sticks/main_input0.txt
new file mode 100644
index 0000000..c12bf91
--- /dev/null
+++ b/codechef/sticks/main_input0.txt
@@ -0,0 +1,5 @@
+2
+5
+1 2 3 1 2
+4
+1 2 2 3
diff --git a/codechef/sticks/main_input1.txt b/codechef/sticks/main_input1.txt
new file mode 100644
index 0000000..636b9ba
--- /dev/null
+++ b/codechef/sticks/main_input1.txt
@@ -0,0 +1,7 @@
+3
+6
+1 1 2 2 3 3
+10
+1 1 3 3 4 4 5 5 5 5
+1
+1 \ No newline at end of file
diff --git a/codechef/sticks/main_output0.txt b/codechef/sticks/main_output0.txt
new file mode 100644
index 0000000..4bbcfcf
--- /dev/null
+++ b/codechef/sticks/main_output0.txt
@@ -0,0 +1,2 @@
+2
+-1
diff --git a/codechef/sticks/main_output1.txt b/codechef/sticks/main_output1.txt
new file mode 100644
index 0000000..89488f4
--- /dev/null
+++ b/codechef/sticks/main_output1.txt
@@ -0,0 +1,3 @@
+6
+25
+-1 \ No newline at end of file