Skip to content

Commit 7b39c59

Browse files
committed
[Silver II] Title: 연속합, Time: 232 ms, Memory: 23724 KB -BaekjoonHub
1 parent 7eca2b1 commit 7b39c59

2 files changed

Lines changed: 22 additions & 19 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
### 성능 요약
66

7-
메모리: 23392 KB, 시간: 236 ms
7+
메모리: 23724 KB, 시간: 232 ms
88

99
### 분류
1010

11-
다이나믹 프로그래밍
11+
다이나믹 프로그래밍, 최대 부분 배열 문제
1212

1313
### 제출 일자
1414

15-
2024년 8월 27일 16:34:59
15+
2024년 1월 11일 21:52:38
1616

1717
### 문제 설명
1818

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
1-
import java.io.*;
2-
import java.nio.Buffer;
3-
import java.util.*;
1+
import java.io.BufferedReader;
2+
import java.io.InputStreamReader;
3+
import java.util.Arrays;
4+
import java.util.StringTokenizer;
5+
46
public class Main {
5-
static int n, ans;
6-
static int[] s;
7-
static StringTokenizer st;
8-
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
8+
static int n, result;
9+
static int[] arr;
910
public static void main(String[] args) throws Exception{
11+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
1012
n = Integer.parseInt(br.readLine());
11-
s = new int[n + 1];
1213

13-
int now;
14-
ans = Integer.MIN_VALUE;
15-
st = new StringTokenizer(br.readLine());
14+
arr = new int[n + 1];
15+
Arrays.fill(arr, -10001);
16+
17+
StringTokenizer st = new StringTokenizer(br.readLine());
18+
result = -10001;
19+
int num;
1620
for (int i = 1; i < n + 1; i++) {
17-
now = Integer.parseInt(st.nextToken());
21+
num = Integer.parseInt(st.nextToken());
22+
arr[i] = Math.max(num, arr[i - 1] + num);
1823

19-
// 지금까지 값 중 최대 값 저장
20-
s[i] = Math.max(s[i - 1] + now, now);
21-
ans = Math.max(ans, s[i]);
24+
result = Math.max(arr[i], result);
2225
}
23-
System.out.println(ans);
26+
System.out.println(result);
2427
}
2528

2629
}

0 commit comments

Comments
 (0)