-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_1912.java
More file actions
36 lines (28 loc) ยท 989 Bytes
/
_1912.java
File metadata and controls
36 lines (28 loc) ยท 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package backjoon;
// https://www.acmicpc.net/problem/1912
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class _1912 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int[] numbers = new int[N];
int[] dp = new int[N]; //๋์ ํฉ์ ์ ์ฅํ๋ ๋ฐฐ์ด dp[2]๋ฉด dp[0]~dp[2]๊น์ง ๋์ ํฉ
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
// numbers๋ฐฐ์ด์ input ์ซ์๋ค ๋ด๊ธฐ
for(int i=0; i<N; i++){
numbers[i] = Integer.parseInt(st.nextToken());
}
// ์ด๊ธฐํ
dp[0] = numbers[0];
int max = numbers[0];
for(int i=1; i<N; i++){
dp[i] = Math.max(dp[i-1]+numbers[i], numbers[i]);
// ์ต๋๊ฐ ๊ฐฑ์
max = Math.max(max, dp[i]);
}
System.out.println(max);
}
}