<문제>

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

 

 

<풀이>

import sys
import heapq
input = sys.stdin.readline

N, H, T = map(int, input().split(' '))
giants_hight_list = []

for _ in range(N):
    giant_hight = -int(input().strip())
    giants_hight_list.append(giant_hight)

heapq.heapify(giants_hight_list)

count = 0

for _ in range(T):
    biggest = -giants_hight_list[0]
    
    if biggest < H or biggest == 1:
        break

    half_hight = biggest // 2
    heapq.heapreplace(giants_hight_list, -half_hight)
    count += 1

biggest = -giants_hight_list[0]
if biggest < H:
    print('YES')
    print(count)
else:
    print('NO')
    print(biggest)

 

- 최대힙 사용

- 가장 큰 놈을 반으로 줄이고 내림까지 처리 (https://en.m.wikipedia.org/wiki/Floor_and_ceiling_functions)

 

+ Recent posts