목차

연속합 2

ps
링크acmicpc.net/…
출처BOJ
문제 번호13398
문제명연속합 2
레벨골드 5
분류

DP

시간복잡도O(n)
인풋사이즈n<=100,000
사용한 언어Python 3.11
제출기록38932KB / 104ms
최고기록104ms
해결날짜2022/12/18

풀이

코드

"""Solution code for "BOJ 13398. 연속합 2".

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

Tags: [DP]
"""

INF = float('inf')


def main():
    n = int(input())  # pylint: disable=unused-variable
    nums = [int(x) for x in input().split()]

    sum_with_del = sum_without_del = answer = -INF
    for num in nums:
        sum_with_del = max(sum_without_del, num + sum_with_del)
        sum_without_del = max(num, num + sum_without_del)
        answer = max(answer, sum_with_del, sum_without_del)

    print(answer)


if __name__ == '__main__':
    main()