diff --git a/MuchanKim/README.md b/MuchanKim/README.md index 8b05ac8..8461760 100644 --- a/MuchanKim/README.md +++ b/MuchanKim/README.md @@ -6,5 +6,6 @@ | 2차시 | 2025.04.11 | 에라토스테네스의채 | [소-난다!](https://www.acmicpc.net/problem/19699)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/10| | 3차시 | 2025.04.29 | 그리디 | [알바생 강호](https://www.acmicpc.net/problem/1758)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/14| | 4차시 | 2025.05.11 | 구현 | [오픈채팅방](https://school.programmers.co.kr/learn/courses/30/lessons/42888)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/20| +| 5차시 | 2025.05.22 | 이분탐색 | [흩날리는 시험지 속에서 내 평점이 느껴진거야](https://www.acmicpc.net/problem/17951)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/25| --- diff --git "a/MuchanKim/\354\235\264\353\266\204\355\203\220\354\203\211/\355\235\251\353\202\240\353\246\254\353\212\224 \354\213\234\355\227\230\354\247\200 \354\206\215\354\227\220\354\204\234 \353\202\264 \355\217\211\354\240\220\354\235\264 \353\212\220\352\273\264\354\247\204\352\261\260\354\225\274.swift" "b/MuchanKim/\354\235\264\353\266\204\355\203\220\354\203\211/\355\235\251\353\202\240\353\246\254\353\212\224 \354\213\234\355\227\230\354\247\200 \354\206\215\354\227\220\354\204\234 \353\202\264 \355\217\211\354\240\220\354\235\264 \353\212\220\352\273\264\354\247\204\352\261\260\354\225\274.swift" new file mode 100644 index 0000000..caacc11 --- /dev/null +++ "b/MuchanKim/\354\235\264\353\266\204\355\203\220\354\203\211/\355\235\251\353\202\240\353\246\254\353\212\224 \354\213\234\355\227\230\354\247\200 \354\206\215\354\227\220\354\204\234 \353\202\264 \355\217\211\354\240\220\354\235\264 \353\212\220\352\273\264\354\247\204\352\261\260\354\225\274.swift" @@ -0,0 +1,43 @@ +import Foundation + +// 그룹 수 1 ~ 10^5 +let input = readLine()!.split(separator: " ").map { Int($0)! } +let group = input[1] + +let scores = readLine()!.split(separator: " ").map { Int($0)! } + +func canMakeGroups(_ scores: [Int], _ target: Int, _ group: Int) -> Bool { + var sum = 0 + var count = 0 + + for score in scores { + sum += score + if sum >= target { + count += 1 + sum = 0 + } + } + + return count >= group +} + +func solution(_ scores: [Int], _ group: Int) -> Int { + var start = 0 + var end = scores.reduce(0, +) + var res = 0 + + while start <= end { + let mid = (start + end) / 2 + + if canMakeGroups(scores, mid, group) { + res = mid + start = mid + 1 + } else { + end = mid - 1 + } + } + + return res +} + +print(solution(scores, group)) \ No newline at end of file