Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a8af6cb

Browse files
[Silver II] Title: 연속합, Time: 160 ms, Memory: 38548 KB -BaekjoonHub
1 parent 453339a commit a8af6cb

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

‎백준/Silver/1912. 연속합/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# [Silver II] 연속합 - 1912
2+
3+
[문제 링크](https://www.acmicpc.net/problem/1912)
4+
5+
### 성능 요약
6+
7+
메모리: 38548 KB, 시간: 160 ms
8+
9+
### 분류
10+
11+
다이나믹 프로그래밍(dp)
12+
13+
### 문제 설명
14+
15+
<p>n개의 정수로 이루어진 임의의 수열이 주어진다. 우리는 이 중 연속된 몇 개의 수를 선택해서 구할 수 있는 합 중 가장 큰 합을 구하려고 한다. 단, 수는 한 개 이상 선택해야 한다.</p>
16+
17+
<p>예를 들어서 10, -4, 3, 1, 5, 6, -35, 12, 21, -1 이라는 수열이 주어졌다고 하자. 여기서 정답은 12+21인 33이 정답이 된다.</p>
18+
19+
### 입력
20+
21+
<p>첫째 줄에 정수 n(1 ≤ n ≤ 100,000)이 주어지고 둘째 줄에는 n개의 정수로 이루어진 수열이 주어진다. 수는 -1,000보다 크거나 같고, 1,000보다 작거나 같은 정수이다.</p>
22+
23+
### 출력
24+
25+
<p>첫째 줄에 답을 출력한다.</p>
26+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# 연속합
2+
n = int(input())
3+
arr = list(map(int, input().split()))
4+
dp = [0] * n
5+
dp[0], ans = arr[0], arr[0]
6+
7+
for i in range(1, n):
8+
dp[i] = max(arr[i], dp[i-1] + arr[i])
9+
ans = max(ans, dp[i])
10+
11+
print(ans)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /