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/2878
🧭 풀이 시간
30분
👀 체감 난이도
✏️ 문제 설명
사탕$M$ 개를 친구 $N$ 명에게 나눠주려 합니다.
각 친구 별로 받고 싶어하는 사탕의 개수가 정해져 있고, 못 받은 사탕 개수의 제곱만큼 분노가 쌓입니다.
사탕을 적절히 나눠 친구들의 분노의 합을 최소로 해야 합니다.
🔍 풀이 방법
사탕을 받아야 하는 친구는, 받지 못한 사탕의 개수가 가장 큰 친구입니다.
이를 매번 구하기에는 시간이 모자랍니다.
내림차순으로 정렬해서$A[i]$ 를 친구 $i$ 가 받아야 하는 사탕 개수라고 정의합시다.
대신 사탕 하나를 줄 때 사람 수만큼 곱해서 생각해야 합니다.
이런 식으로 반복문 한 번에 친구들에게 사탕을 모두 나누어줄 수 있습니다.
⏳ 회고
Java는 부호없는 자료형을 지원하지 않아서 BigInteger에 대해 알아보고 사용해봤습니다. BigInteger를 처음 접하다보니, 사용법을 잘 몰라 디버깅하는데 오래 걸렸습니다.