Agorithm/백준 알고리즘
백준 알고리즘 18111번 마인크래프트 (python)
kimjinho1
2021. 3. 6. 00:09
728x90
반응형
브루트포스 알고리즘 & 구현 문제이다.
높이의 범위가 정해져 있어서 257가지(0~256)의 시간을 다 확인해보면 쉽게 풀 수 있다.
sys.stdin.readline을 사용해야 하고 PyPy3로 제출해야 통과된다.
import sys
N, M, B = map(int, sys.stdin.readline().split())
li = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
time, height = 9223372036854775807, 0
for h in range(257):
bot = top = 0
for i in range(N):
for j in range(M):
if li[i][j] < h:
bot += h-li[i][j]
else:
top += li[i][j]-h
if bot > top + B:
continue
t = bot + top*2
if t <= time:
time = t
height = h
print(time, height)
728x90
반응형