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/1202
🧭 풀이 시간
60분
👀 체감 난이도
✏️ 문제 설명
Ci 의 무게만큼 담을 수 있는 가방 K개와
Mi 의 무게, Vi의 가치가 있는 보석 N개가 주어졌을 때
각 가방에 보석을 1개씩 담았을 때, 가져갈 수 있는 보석의 가치의 최대치를 구하는 문제입니다.
🔍 풀이 방법
보석 클래스를 만들어서 정렬을 이용하여 풀었습니다.
각 무게가 주어진 가방의 배열을 무게 오름차순으로 정렬하고 작은 무게 제한의 가방부터 순회했습니다.
이 때 각 가방 무게의 제한보다 작은 보석들을 가치 역순 pq에 넣어 주었습니다.
현재 가방에 들어갈 수 있는 보석은 다음 가방에도 무조건 넣을 수 있기 때문에 해당 pq를 계속 유지합니다.
그러면서 각 가방마다 첫번째 값을 꺼내면 그 값은 pq로 정렬되어 있기 때문에 가치가 가장 높습니다.
이를 이용해서 풀었습니다.
⏳ 회고
처음에 단순하게 모든 경우의 수를 돌았는데 시간초과가 났고
그 다음에는 ArrayList를 이용했는데도 시간초과가 나서
이를 해결하기 위해서 고민을 많이 해야됐던 것 같습니다.