백준 :: 물병 <1052번>

혜 콩·2022년 7월 25일
0

알고리즘

목록 보기
39/61

> 문제 <

https://www.acmicpc.net/problem/1052

> 풀이 <

> 코드 <

# clone (pypy만 통과, python 시간초과)

import sys

n, k = map(int, sys.stdin.readline().split())


def bottle(num):
    b = 0                   # 총 물병 갯수
    while 1:
        twin = num // 2
        remain = num % 2
        b += remain
        num = twin
        if num == 0:              # 끝까지 1병으로 합쳤을 때
            break
    return b


if k >= n:
    print(0)
else:
    buy = n
    while 1:
        if bottle(buy) <= k:
            print(buy - n)
            break
        else:
            buy += 1
profile
배우고 싶은게 많은 개발자📚

0개의 댓글