본문 바로가기
알고리즘/백준

[백준]230121 문제풀이

by stubborngastropod 2023. 1. 21.
728x90

18111. 마인크래프트

import sys

N, M, B = map(int, sys.stdin.readline().split())
land = []

for i in range(N):
    block = list(map(int, sys.stdin.readline().split()))
    land = land + block

max_height = max(land)
min_height = min(land)
shortest_time = 64000000

for i in range(min_height, max_height + 1):
    spendtime = 0
    spendblock = 0
    for j in land:
        if j <= i:
            spendtime += (i - j)
            spendblock += i - j
        else:
            spendtime += (j - i) * 2

    if spendblock <= B and spendtime <= shortest_time:
        shortest_time = spendtime
        final_height = i

print(f'{shortest_time} {final_height}')

예제 문제도 잘 풀리고, 브루트포싱인데... 자꾸 시간초과가 왜 뜨는지 모르겠다. sys도 쓰고 pypy로도 돌려봤는데 안되는걸 보니 코드를 다시 고민해봐야겠다

728x90

'알고리즘 > 백준' 카테고리의 다른 글

[백준]230125 문제풀이  (0) 2023.01.25
[백준]230124 문제풀이  (0) 2023.01.24
[백준]230119 문제풀이  (0) 2023.01.20
[백준]230118 문제풀이  (0) 2023.01.18
[백준]230117 문제풀이  (0) 2023.01.17

댓글