20250727 baekjoon

This commit is contained in:
songyc macbook 2025-07-27 22:11:51 +09:00
parent 98f68a7c7e
commit a29dfc5042

View File

@ -0,0 +1,37 @@
import sys
input = sys.stdin.readline
N, M, B = map(int, input().split())
blockList = [0]*257
for _ in range(N):
for height in map(int, input().split()):
blockList[height] += 1
min_time = float('inf')
best_height = -1
for target_height in range(257):
inventory = B
time = 0
for current_height in range(256):
if blockList[current_height] == 0 :
continue
if current_height > target_height:
diff = current_height - target_height
count = blockList[current_height]
inventory += diff*count
time += 2*diff*count
else:
diff = target_height - current_height
count = blockList[current_height]
inventory -= diff*count
time += diff*count
if inventory >= 0:
if time < min_time:
min_time = time
best_height = target_height
result = ' '.join([str(min_time), str(best_height)]) + '\n'
sys.stdout.write(result)