From 3154dbd6c43e83e8f3354834ff2c27f107368d84 Mon Sep 17 00:00:00 2001 From: sh0723 Date: Thu, 3 Sep 2026 15:34:14 +0900 Subject: [PATCH 1/2] =?UTF-8?q?14627=20:=20=ED=8C=8C=EB=8B=AD=ED=8C=8C?= =?UTF-8?q?=EB=8B=AD=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week6/BOJ14627/BOJ14627_V1.cpp | 45 ++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/week6/BOJ14627/BOJ14627_V1.cpp diff --git a/src/week6/BOJ14627/BOJ14627_V1.cpp b/src/week6/BOJ14627/BOJ14627_V1.cpp new file mode 100644 index 0000000..2452c6c --- /dev/null +++ b/src/week6/BOJ14627/BOJ14627_V1.cpp @@ -0,0 +1,45 @@ +#include +using namespace std; +int N,M; +vector inp; +bool check(int num) { + int cnt = 0, ret = 0; + for (int i=0; i= M; +} +int main() { + + ios_base::sync_with_stdio(false); + cin.tie(nullptr); + cout.tie(nullptr); + + + cin >> N >> M; + long long int low=1, high=LONG_MAX,mid; + long long int sum=0; + for (int i=0; i> num; + inp.push_back(num); + sum += num; + high = min(high, num); + } + + int ret=1; + while(low <= high) { + mid = (low + high) / 2; + if (check(mid)) { + ret = mid; + low = mid + 1; + } else { + high = mid - 1; + } + } + + int result = sum - ret * M; + cout << result << '\n'; + return 0; +} \ No newline at end of file From 36e740a9652d32da3a9ba6faab2e29d1ea335171 Mon Sep 17 00:00:00 2001 From: sh0723 Date: Thu, 3 Sep 2026 15:38:29 +0900 Subject: [PATCH 2/2] =?UTF-8?q?14627=20:=20=ED=8C=8C=EB=8B=AD=ED=8C=8C?= =?UTF-8?q?=EB=8B=AD=20=ED=83=90=EC=83=89=20=EB=B2=94=EC=9C=84=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week6/BOJ14627/BOJ14627_V1.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/week6/BOJ14627/BOJ14627_V1.cpp b/src/week6/BOJ14627/BOJ14627_V1.cpp index 2452c6c..765ea05 100644 --- a/src/week6/BOJ14627/BOJ14627_V1.cpp +++ b/src/week6/BOJ14627/BOJ14627_V1.cpp @@ -2,13 +2,14 @@ using namespace std; int N,M; vector inp; -bool check(int num) { - int cnt = 0, ret = 0; +bool check(long long int num) { + long long int cnt = 0; for (int i=0; i= M) return true; } - return cnt >= M; + return false; } int main() { @@ -18,17 +19,17 @@ int main() { cin >> N >> M; - long long int low=1, high=LONG_MAX,mid; + long long int low=1, high=0,mid; long long int sum=0; for (int i=0; i> num; inp.push_back(num); sum += num; - high = min(high, num); + high = max(high, num); } - int ret=1; + long long int ret=0; while(low <= high) { mid = (low + high) / 2; if (check(mid)) { @@ -39,7 +40,7 @@ int main() { } } - int result = sum - ret * M; + long long int result = sum - ret * M; cout << result << '\n'; return 0; -} \ No newline at end of file +}