-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj1912.java
More file actions
41 lines (31 loc) · 978 Bytes
/
boj1912.java
File metadata and controls
41 lines (31 loc) · 978 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
37
38
39
40
41
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class boj1912 {
static int n;
static int[] arr, dp;
public static void main(String[] args) throws IOException {
input();
recur(n);
}
static void input() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt(br.readLine());
dp = new int[n];
arr = new int[n];
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
}
static void recur(int num) {
int max = arr[0];
dp[0] = arr[0];
for (int i = 1; i < num; i++) {
dp[i] = Math.max(dp[i - 1] + arr[i], arr[i]);
max = Math.max(max, dp[i]);
}
System.out.println(max);
}
}