PS/브루트포스
[백준] No.18111_마인크래프트 完
_빌런
2023. 7. 14. 18:16
# ---------- Import ----------
import sys
input = sys.stdin.readline
# ---------- Main ----------
minTime, maxHeight = 1e9, -1
ground = dict()
row, col, inventory = map(int, input().split())
# Dictionary initalization
for _ in range(row):
for i in map(int, input().split()):
ground[i] = ground.get(i, 0) + 1
keys = ground.keys()
# Brute Force
for currentH in range(min(keys), max(keys)+1):
difList = [(currentH - height) * count for height, count in ground.items()]
needBlock = sum(difList)
spendTime = sum(map(lambda x: x if x > 0 else -2 * x, difList))
# Checking inventory
if needBlock <= inventory:
minTime = min(minTime, spendTime)
if minTime == spendTime:
maxHeight = max(maxHeight, currentH)
print(minTime, maxHeight)