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