연속합 (1912) 본문
728x90
n = int(input())
nums = list(map(int, input().split()))
sum = 0
max = nums[0]
for num in nums:
sum += num
if sum > 0:
if max < sum:
max = sum
else:
sum = 0
print(max)
# -2 -1 -3 -4 인 경우 에러
###############
n = int(input())
nums = list(map(int, input().split()))
sum = 0
max = nums[0]
for num in nums:
sum += num
if sum > 0:
if max < sum:
max = sum
else:
if max < num:
max = num
else:
sum = 0
print(max)
# 수정
'Algorithms > DP (Dynamic Programming)' 카테고리의 다른 글
2차원 배열의 합 [2167] with 파이썬 (0) | 2020.06.05 |
---|---|
전깃줄 (2565) (0) | 2020.05.19 |
RGB 거리 (1149) (0) | 2020.05.19 |
파도반 수열 (9641) (0) | 2020.05.19 |
피보나치 함수 (1003) (0) | 2020.05.19 |
Comments