Skip to content

Commit fc3eea1

Browse files
committed
atcoder/abc071C
1 parent 1ae2574 commit fc3eea1

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

atcoder/abc071/C/main.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = long long;
5+
6+
int N;
7+
vector<int> A;
8+
9+
ll solve() {
10+
map<int,int> mp;
11+
for (auto v : A) {
12+
++mp[v];
13+
}
14+
15+
ll ans = 0;
16+
deque<int> Q;
17+
for (auto e : mp) {
18+
auto v = e.first, c = e.second;
19+
if (c <= 1) continue;
20+
if (c >= 4) {
21+
ans = max(ans, ll(v) * v);
22+
}
23+
Q.push_back(v);
24+
if (Q.size() < 2) continue;
25+
if (Q.size() > 2) Q.pop_front();
26+
ans = max(ans, ll(Q[0]) * Q[1]);
27+
}
28+
return ans;
29+
}
30+
31+
int main() {
32+
ios_base::sync_with_stdio(false);
33+
cin.tie(0); cout.tie(0);
34+
35+
cin >> N;
36+
A.assign(N, 0);
37+
for (int i = 0; i < N; ++i) {
38+
cin >> A[i];
39+
}
40+
cout << solve() << endl;
41+
42+
return 0;
43+
}

0 commit comments

Comments
 (0)