목차

내려가기

ps
링크acmicpc.net/…
출처BOJ
문제 번호2096
문제명내려가기
레벨골드 4
분류

DP

시간복잡도O(n)
인풋사이즈n<=100,000
사용한 언어Python
제출기록29200KB / 300ms
최고기록292ms
해결날짜2021/08/12

풀이

코드

"""Solution code for "BOJ 2096. 내려가기".

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

Tags: [DP]
"""

import sys


def main():
    N = int(sys.stdin.readline())
    min_l = min_m = min_r = max_l = max_m = max_r = 0
    for _ in range(N):
        l, m, r = [int(x) for x in sys.stdin.readline().split()]
        min_l, min_m, min_r = (min(min_l, min_m) + l,
                               min(min_l, min_m, min_r) + m,
                               min(min_m, min_r) + r)
        max_l, max_m, max_r = (max(max_l, max_m) + l,
                               max(max_l, max_m, max_r) + m,
                               max(max_m, max_r) + r)

    print(max(max_l, max_m, max_r), min(min_l, min_m, min_r))


if __name__ == '__main__':
    main()