From adb97626f5553013e2758aeb136c8ffd28436627 Mon Sep 17 00:00:00 2001 From: omagdy7 Date: Mon, 18 Jul 2022 22:11:40 +0200 Subject: Solved a couple of problems --- codechef/sticks/main | Bin 0 -> 85968 bytes codechef/sticks/main.cpp | 42 +++++++++++++++++++++++++++++++++++++++ codechef/sticks/main_input0.txt | 5 +++++ codechef/sticks/main_input1.txt | 7 +++++++ codechef/sticks/main_output0.txt | 2 ++ codechef/sticks/main_output1.txt | 3 +++ 6 files changed, 59 insertions(+) create mode 100755 codechef/sticks/main create mode 100644 codechef/sticks/main.cpp create mode 100644 codechef/sticks/main_input0.txt create mode 100644 codechef/sticks/main_input1.txt create mode 100644 codechef/sticks/main_output0.txt create mode 100644 codechef/sticks/main_output1.txt (limited to 'codechef') diff --git a/codechef/sticks/main b/codechef/sticks/main new file mode 100755 index 0000000..ebd7c57 Binary files /dev/null and b/codechef/sticks/main 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 + +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 v(n); + map mp; + for (int &x : v) { + cin >> x; + mp[x]++; + } + vector pair; + set 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 -- cgit v1.2.3