Hanbit the Developer

[DP] Python - 1912번, 연속합 본문

Algorithm/백준

[DP] Python - 1912번, 연속합

hanbikan 2021. 3. 8. 16:16

www.acmicpc.net/problem/1912

 

1912번: 연속합

첫째 줄에 정수 n(1 ≤ n ≤ 100,000)이 주어지고 둘째 줄에는 n개의 정수로 이루어진 수열이 주어진다. 수는 -1,000보다 크거나 같고, 1,000보다 작거나 같은 정수이다.

www.acmicpc.net

N = int(input())
nums=list(map(int, input().split()))
dp = [nums[0]]
for i in range(1, N):
    dp.append(max(dp[i-1]+nums[i], nums[i]))
print(max(dp))