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/21758
🧭 풀이 시간
60분
👀 체감 난이도
✏️ 문제 설명
N개의 장소가 일렬로 있음.
이중 벌통은 하나고 벌은 두 마리가 각각 장소에 있을 수 있음.
벌들은 벌통을 향해 날아가고 자기가 출발한 장소를 제외한 경로에 꿀들을 다 먹음.(벌통위치 포함) 꿀들은 N개에 장소에 양수로 주어짐.
이때 벌 두마리가 가장 많은 꿀을 먹었을 때, 그 꿀의 양을 출력.
🔍 풀이 방법
누적합.
왼쪽에서 꿀을 수집하는 경우와 오른쪽으로 수집하는 경우로 누적합을 계산해둠.
벌통이 왼쪽 끝, 벌 한마리가 오른쪽 끝에 있는 경우,
벌통이 오른쪽 끝, 벌 한마리가 왼쪽 끝에 있는 경우,
벌 한마리가 왼쪽 끝, 한마리가 오른쪽 끝에 있는 경우로 케이스를 분류하고
남은 벌 또는 벌통을 배치하며 꿀의 최댓값을 구함.
⏳ 회고
벌통을 N번 배치하고 벌들이 오른쪽 끝에 두 마리 붙어있는 경우, 양쪽에 있는 경우, 오른쪽 끝에 두 마리 붙어있는 경우를 보았는데, 아이디어는 비슷했으나 생각해보니 벌들이 시작위치의 꿀을 먹지 못하기 때문에, 무작정 끝에 붙여놓는 것은 최적이 아니었음.
그렇다고 벌통만 붙여놓고 벌들을 각각 배치하는 건 N^2이 되니까 시간이 안됨.
핵심은 3가지의 변수가 있으니 두 개를 고정하고 하나만을 N번 반복해서 최적을 찾는 것이었음. 누적합은 어렵다...