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/1889
🧭 풀이 시간
30분
👀 체감 난이도
✏️ 문제 설명
캠프의 마지막 날에 선물 교환 이벤트를 하려고 한다. 모든 학생들이 각자 두 개씩 선물을 준비해 와서 두 명의 친구에게 주는 것이다. 이벤트를 준비하던 중, 조교들은 이러한 이벤트가 불화를 일으킬 수 있음을 알게 되었다. 참석한 학생들 중 일부 학생들은 선물을 못 받거나 하나만 받게 되는 데 비해, 인기가 많은 학생들은 선물을 세 개 또는 그 이상 받게 되는 것이다.
그래서 조교들은 모든 학생들이 두 개의 선물을 주고, 또한 모든 학생들이 정확히 두 개의 선물만을 받도록 이벤트를 준비하고자 한다. 이를 위해 각각의 학생이 선물을 주고자 하는 두 명의 학생이 누구인지를 미리 알아내었다. 리스트를 살펴보던 조교들은, 몇 명의 학생을 추려 내면 모든 학생이 정확히 두 개의 선물을 받을 수 있다는 것을 알게 되었다.
참여한 모든 학생이 정확히 선물을 두 개씩 받도록 이벤트에 참여할 학생들을 결정하는 프로그램을 작성하시오. 단, 이벤트에 참여하는 학생의 수가 최대가 되도록 해야 한다.
🔍 풀이 방법
간단하게 생각해보면, 누군가가 2개 초과로 선물을 받고 있으면, 반드시 누군가는 2개 미만을 받고 있다. 그렇기에 받는 선물을 기준으로 PQ에 넣은 후, 2개 미만 계속해서 제거하면 된다.
⏳ 회고