• Home
  • About
    • Seokmin.Lee photo

      Seokmin.Lee

      Hello, I am a master's student in the Department of Convergence Security (Samsung Advanced Security) at Korea University.After graduation, I am expected as a security developer or researcher member of Samsung SDS.

    • Learn More
    • LinkedIn
    • Github
  • Posts
    • All Tags

[til][bj2343]기타레슨

17 Jan 2025

문제:

  • 제목: 기타 레슨
  • 링크 : https://www.acmicpc.net/problem/2343
  • 접근 방법 : 탐색

해결 방식:

# 기타 레슨

N, M = map(int, input().split())
lecture = list(map(int, input().split(' ')))

start = 0
end = 0

for i in range(N):
    if start < lecture[i]:  # 최대 길이의 레슨
        start = lecture[i]
    end += lecture[i]  # 모든 레슨 길이의 합

while start <= end:
    middle = int((start + end) / 2)
    count = 0
    sum = 0

    for i in range(N):
        if sum + lecture[i] > middle:
            count += 1
            sum = 0  # 초기화
        sum += lecture[i]

    if sum != 0:
        count += 1

    if count > M:
        start = middle + 1
    else:
        end = middle - 1

print(start)




PSPYTHONBJTIL항해 Share Tweet +1