Problem Solving/Baekjoon
[백준] 24498 blobnom - Greedy / Java
graycode
2023. 5. 16. 12:11
• 문제 링크
24498번: blobnom
블롭들은 심심해서 서로를 이용해 $N$개의 탑을 만들었다. 각 탑의 높이는 그 탑에 있는 블롭의 수와 같다. 여러분은 다음 행동을 $0$회 이상 할 수 있다. 처음과 마지막이 아닌 탑 중 하나를 선
www.acmicpc.net
• 풀이 과정
• 풀이 코드
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());
int[] arr = new int[n];
while (n-- > 0)
arr[n] = Integer.parseInt(st.nextToken());
int max = 0;
for (int i = 1; i < arr.length - 1; i++)
max = Math.max(max, arr[i] + Math.min(arr[i - 1], arr[i + 1]));
bw.write(String.valueOf(Math.max(max, Math.max(arr[0], arr[arr.length - 1]))));
bw.flush();
}
}