백준 27896번: 특별한 서빙 #Python

ColorlessDia·2025년 3월 11일

algorithm/baekjoon

목록 보기
478/815
from heapq import heappush, heappop

N, M = map(int, input().split())
x_sequence = map(int, input().split())

negative = 0
eggplant = 0
x_list = []

for x in x_sequence:
    negative += x
    heappush(x_list, -x)

    if negative < M:
        continue
    
    negative += heappop(x_list) * 2
    eggplant += 1

print(eggplant)

0개의 댓글