티스토리 뷰

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);
}
}



모르겠다... 코드는 엄청 간단한데 생각을 못하겠다

댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/02   »
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
글 보관함