반응형
public class Main {
private static final int MAX = 100000;
private static final int[] D = new int[MAX+1];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String readLine = br.readLine();
String[] split = readLine.split(" ");
int[] a = new int[n+1];
a[0] = -1;
for (int i = 0; i < split.length; i++) {
a[i+1] = Integer.parseInt(split[i]);
}
int max = 1;
for(int j = 1; j <= n; j++) {
D[j] = a[j];
if(D[j] < D[j-1]+a[j]) {
D[j] = D[j-1]+a[j];
}
if(D[max] < D[j]) {
max = j;
}
}
System.out.println(D[max]);
}
}
반응형
'Algorithm > 백준 문제풀이' 카테고리의 다른 글
백준 14002 - 가장 긴 증가하는 부분 수열 4(자바 구현) (0) | 2022.03.10 |
---|---|
백준 11053 - 가장 긴 증가하는 부분 수열(자바 구현) (0) | 2022.03.08 |
백준 1676 - 팩토리얼 0의 개수(자바 구현) (0) | 2022.03.03 |
백준 10872 - 팩토리얼(자바 구현) (0) | 2022.03.03 |
백준 6588 - 골드바흐의 추측(자바 구현) (0) | 2022.02.26 |