From 0d8c7580c52decdb018a90d371ce5825e0531894 Mon Sep 17 00:00:00 2001 From: ji-junhyuk Date: Thu, 2 Feb 2023 09:53:01 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20solve=202295,=20=EC=84=B8=EC=88=98?= =?UTF-8?q?=EC=9D=98=20=ED=95=A9(binary=5Fsearch,=20g4,=2040m)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- junji/binary_search/2295.cpp | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 junji/binary_search/2295.cpp 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); + } + } + } +}