목차

마인크래프트

ps
링크acmicpc.net/…
출처BOJ
문제 번호18111
문제명마인크래프트
레벨실버 3
분류

브루트포스

시간복잡도O(n*m + h)
인풋사이즈n<=500, m<=500, h<=256
사용한 언어Python
제출기록32084KB / 188ms
최고기록136ms
해결날짜2021/10/17

풀이

코드

"""Solution code for "BOJ 18111. 마인크래프트".

- Problem link: https://www.acmicpc.net/problem/18111
- Solution link: http://www.teferi.net/ps/problems/boj/18111
"""

import collections


def main():
    # pylint: disable=unused-variable
    N, M, B = [int(x) for x in input().split()]
    count_by_height = collections.Counter()
    for _ in range(N):
        heights = [int(x) for x in input().split()]
        count_by_height.update(heights)

    all_block_count = sum(
        height * count for height, count in count_by_height.items())
    max_height = max(count_by_height)

    shorter_count = 0
    taller_count = N * M - count_by_height[0]
    inven = B + all_block_count
    min_time = time = all_block_count * 2
    height_at_min_time = 0
    for height in range(1, max_height + 1):
        shorter_count += count_by_height[height - 1]
        inven -= taller_count + shorter_count
        if inven < 0:
            break
        time -= taller_count * 2 - shorter_count
        taller_count -= count_by_height[height]
        if time <= min_time:
            min_time, height_at_min_time = time, height

    print(min_time, height_at_min_time)


if __name__ == '__main__':
    main()