티스토리 뷰
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class Main {
static int d[];
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int count = Integer.parseInt(in.readLine());
String[] input = in.readLine().split(" ");
int[] sequence = new int[count];
for(int i=0;i<count;++i) {
sequence[i] = Integer.parseInt(input[i]);
}
d = new int[count];
for(int i=0;i<count;++i) {
d[i] = sequence[i];
if(i == 0) continue;
if(d[i] < d[i-1] + sequence[i]) {
d[i] = d[i-1] + sequence[i];
}
}
int result = Integer.MIN_VALUE;
for(int i: d) {
if(result < i) {
result = i;
}
}
System.out.println(result);
}
}
모르겠다... 코드는 엄청 간단한데 생각을 못하겠다
'Algorithm > Baekjoon Online Judge' 카테고리의 다른 글
1934번 '최소공배수' (0) | 2018.07.31 |
---|---|
2609번 '최대공약수와 최소공배수' (0) | 2018.07.31 |
11722번 '가장 긴 감소하는 부분 수열' (0) | 2018.07.29 |
11055번 '가장 큰 증가 부분 수열' (0) | 2018.07.29 |
11053번 '가장 긴 증가하는 부분 수열' (0) | 2018.07.29 |
댓글