From 9562d073950f307b136632094a86a5b6745d94a4 Mon Sep 17 00:00:00 2001 From: ji-junhyuk Date: Fri, 3 Feb 2023 22:09:03 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20solve=201654,=20=EB=9E=9C=EC=84=A0=20?= =?UTF-8?q?=EC=9E=90=EB=A5=B4=EA=B8=B0(parametric=20search,=20s2,=202h)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- junji/binary_search/1654.cpp | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 junji/binary_search/1654.cpp diff --git a/junji/binary_search/1654.cpp b/junji/binary_search/1654.cpp new file mode 100644 index 0000000..c915784 --- /dev/null +++ b/junji/binary_search/1654.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +int N, K; +int lan[10000]; +int Max; + +void get_input() +{ + cin >> N >> K; + for (int i = 0; i < N; ++i) + { + cin >> lan[i]; + if (Max < lan[i]) + Max = lan[i]; + } +} + +long long b_search(long long left, long long right) +{ + long long ans = 0; + while (left <= right) + { + long long mid = (left + right) / 2; + long long cnt = 0; + for (int i = 0; i < N; ++i) + cnt += lan[i] / mid; + if (cnt < K) + { + right = mid - 1; + } + else + { + ans = mid; + left = mid + 1; + } + } + return (ans); +} + +int main(void) +{ + ios::sync_with_stdio(false); + cin.tie(NULL); + + get_input(); + cout << (b_search(1, Max)); +}