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