Problem Solving/BOJ
[Silver 1] 2156번 포도주 시식
kmkunk
2022. 3. 29. 18:27
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int[] k = new int[10001];
int[] dp = new int[10001];
for(int i=1; i<=n; i++) { k[i] = Integer.parseInt(br.readLine()); }
dp[1] = k[1];
dp[2] = k[1]+k[2];
for(int i=3; i<=n; i++) {
dp[i] = Math.max(dp[i-1], Math.max(dp[i-2]+k[i], dp[i-3]+k[i-1]+k[i]));
}
System.out.println(dp[n]);
}
}