목차

내려가기 2

ps
링크acmicpc.net/…
출처BOJ
문제 번호15645
문제명내려가기 2
레벨실버 1
분류

DP

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

풀이

코드

"""Solution code for "BOJ 15645. 내려가기 2".

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

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()