Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🧷 문제 링크
https://www.acmicpc.net/problem/35113
🧭 풀이 시간
20분
👀 체감 난이도
✏️ 문제 설명
N개의 양의 정수로 이루어진 배열 A가 주어진다.
1 <= i < j < k < N인 i, j, k에 대해,
f(i, j, k) = max(A[1], ..., A[i]) + max(A[i+1], ..., A[j]) + max(A[j+1], ..., A[k]) + max(A[k+1], ..., A[N])이라 하자.
가능한 f(i, j, k)의 값 중 최솟값을 구해보자.
🔍 풀이 방법
j를 고정시키면 배열이 두 개로 쪼개지게 된다.
구간 [1, j]와 [j+1, N]을 각각 다시 한 번 쪼개야 한다.
구간 [1,j]를 [1,i], [i+1,j]로 쪼갤 때,
이 구간의 최댓값이 [1,i]에 속하게 되는 경우에는 max(A[i+1], ..., A[j])를 최소화해야 한다. -> i = j-1이어야 한다.
반대로, 이 구간의 최댓값이 [i+1,j]에 속하게 되는 경우에는 max(A[1], ..., A[i])를 최소화해야 한다. -> i = 1이어야 한다.
즉, 구간 [1,j]를 쪼개는 최적의 방법은 항상 [1,1], [2,j] 혹은 [1,j-1], [j,j] 이다.
마찬가지로, 구간 [j+1,N]을 쪼개는 최적의 방법은 항상 [j+1,j+1], [j+2,N] 혹은 [j+1,N-1], [N,N] 이다.
j를 이동시키며 위 값들을 확인해주었다.
누적 max를 관리하는 배열을 통해 정답을 갱신해나갔다.
⏳ 회고
누적 max, min은 항상 단조성을 지닌다는 것을 자연스럽게 떠올릴 수 있는 좋은 문제인 것 같다