-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBAEKJOON_13398
More file actions
55 lines (43 loc) · 1.3 KB
/
BAEKJOON_13398
File metadata and controls
55 lines (43 loc) · 1.3 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
import org.w3c.dom.Node;
import java.io.*;
import java.math.BigInteger;
import java.sql.Array;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int N = Integer.parseInt(br.readLine());
int[] A = new int[N];
int[] D = new int[N];
int[] D2 = new int[N];
StringTokenizer st = new StringTokenizer(br.readLine());
for(int i=0; i<N; i++){
A[i] = Integer.parseInt(st.nextToken());
}
for(int i=0; i<N; i++){
D[i]= A[i];
if(i>0 && D[i] < D[i-1] +A[i]){
D[i] = D[i-1] +A[i];
}
}
for(int i=N-1; i>=0; i--){
D2[i] = A[i];
if (i < N - 1 && D2[i] < D2[i + 1] + A[i]) {
D2[i] = D2[i+1]+A[i];
}
}
int ans = D[0];
for(int i=1; i<N; i++){
if(ans < D[i] ){
ans =D[i];
}
}
for(int i=1; i<N-1; i++){
if (ans < D[i-1] + D2[i+1]) {
ans = D[i-1]+D2[i+1];
}
}
System.out.println(ans);
}
}