diff --git a/junji/binary_search/2295.cpp b/junji/binary_search/2295.cpp new file mode 100644 index 0000000..dc6c3dd --- /dev/null +++ b/junji/binary_search/2295.cpp @@ -0,0 +1,53 @@ +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +int N; +int U[1000]; +vector two; + +void get_input() +{ + cin >> N; + for (int i = 0; i < N; ++i) + { + cin >> U[i]; + } + sort(U, U + N); + int idx = 0; + for (int i = 0; i < N; ++i) + { + for (int j = i; j < N; ++j) + two.push_back(U[i] + U[j]); + } + sort(two.begin(), two.end()); +// for (int i = 0; i < two.size(); ++i) +// { +// cout << two[i] << ' '; +// } +} + +int main(void) +{ + ios::sync_with_stdio(false); + cin.tie(NULL); + + get_input(); + for (int i = N - 1; i > 0; --i) + { + for (int j = 0; j < N; ++j) + { + int find = U[i] - U[j]; + if (binary_search(two.begin(), two.end(), find)) + { + cout << U[i]; + return (0); + } + } + } +}