-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.cpp
38 lines (30 loc) · 917 Bytes
/
1.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
// 1 Complexity : O(N log N)
// 2 Complexity : O(N^2 log N)
#include <bits/stdc++.h>
using namespace std;
#define PART2
int main() {
// Number of entries in the input file
constexpr int N = 200;
vector<int> inputs(N);
for (int i = 0; i < N; ++i)
cin >> inputs[i];
sort(inputs.begin(), inputs.end());
#ifdef PART1
for (int i = 0; i < N; ++i)
if (binary_search(inputs.begin(), inputs.end(), 2020 - inputs[i])) {
cout << (2020 - inputs[i]) * inputs[i] << endl;
return 0;
}
#else
for (int i = 0; i < N; ++i)
for (int j = i + 1; j < N; ++j)
if (binary_search(inputs.begin(), inputs.end(), 2020 - inputs[i]
- inputs[j])) {
cout << (2020 - inputs[i] - inputs[j]) * inputs[i] * inputs[j]
<< endl;
return 0;
}
#endif
return -1;
}