-
Notifications
You must be signed in to change notification settings - Fork 2
/
Main.java
33 lines (25 loc) Β· 834 Bytes
/
Main.java
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
package DP.P1912;
import java.io.*;
import java.util.*;
public class Main {
static int n;
static int[] arr, dp;
public static void main(String[] args) throws Exception {
System.setIn(new FileInputStream("src/DP/P1912/input.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt(br.readLine());
arr = new int[n];
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
dp = new int[n];
dp[0] = arr[0];
int ans = dp[0];
for (int i = 1; i < n; i++) {
dp[i] = Math.max(dp[i-1], 0) + arr[i];
ans = Math.max(ans, dp[i]);
}
System.out.println(ans);
}
}