반응형
https://www.acmicpc.net/problem/1912
package com.ji.beakjoon.dp;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
/**
*
* @author ji
*
*/
public class ConsecutiveSum {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
Integer numberCount = Integer.valueOf(br.readLine());
int[] dp = new int[numberCount];
int[] numbersArr = new int[numberCount];
String[] inputNumbers = br.readLine().split(" ");
for (int i = 0; i < numberCount; i++)
numbersArr[i] = Integer.valueOf(inputNumbers[i]);
dp[0] = numbersArr[0];
int max = numbersArr[0];
//bottom-up
for(int i =1 ; i<numberCount; i++ ) {
dp[i] = Math.max(dp[i-1]+numbersArr[i], numbersArr[i]);
max = Math.max(max, dp[i]);
}
bw.write(String.valueOf(max));
br.close();
bw.flush();
bw.close();
}
}
728x90
'[개발관련] > 코테준비' 카테고리의 다른 글
[백준] 늑대와 양 (0) | 2021.08.07 |
---|---|
[백준] 스티커 (0) | 2021.07.18 |
[백준] 공유기 설치 (0) | 2021.07.18 |
[백준] 아기상어 (0) | 2021.07.18 |
[백준] 출석체크 (0) | 2021.07.11 |