-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1912.java
More file actions
29 lines (27 loc) · 862 Bytes
/
1912.java
File metadata and controls
29 lines (27 loc) · 862 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int arr[]=new int[n];
StringTokenizer st = new StringTokenizer(br.readLine()," ");
for(int i=0; i<n; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
int dp[]=new int[n];
dp[0]=arr[0];
int max=dp[0];
for(int i=1; i<n; i++){
if(dp[i-1]+arr[i]>=arr[i])
dp[i]=dp[i-1]+arr[i];
else
dp[i]=arr[i];
if(max<=dp[i])
max=dp[i];
}
System.out.println(max);
}
}