검색결과 리스트
글
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
long dp[][] = new long[N][2];
st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
dp[i][0] =Integer.parseInt(st.nextToken());
}
long max = -1;
if(dp[0][0]> 0) {
dp[0][1] = dp[0][0];
}
max = dp[0][0];
for (int i = 1; i < N; i++) {
dp[i][1] = dp[i-1][1]+dp[i][0] > dp[i][0] ? dp[i-1][1]+dp[i][0] :dp[i][0];
max = dp[i][1] > max ? dp[i][1] : max ;
}
System.out.println(max);
}
}
'알고리즘' 카테고리의 다른 글
JAVA 백준 1463번 1로 만들기 (0) | 2020.02.06 |
---|---|
JAVA 백준 1000번 A+B (0) | 2020.02.06 |
RECENT COMMENT