You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This discussion was converted from issue #109 on September 15, 2026 11:09.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Problem link
https://leetcode.com/problems/put-marbles-in-bags
Problem Summary
가방 안의 돌들을 k 그룹으로 묶을 때 최소 합과 최대 합의 차이를 구하는 문제.
Solution
처음에는 DP 느낌이지만 수가 너무 많다.
정답은 그리디로 가면 된다.
뭔가 정렬 느낌이긴 했는데 잘 안돼서 에디토리얼 참고함.
사진은 에디토리얼에서 가져옴

일단 시작 돌과 마지막 돌은 무조건 포함해야 하니 제외하자. 그러면 k-1번 가방의 돌들을 나누는 문제가 된다. 여기서 나눌 때 더해지는 값은 잘린 부분의 양쪽 값. 이 2개의 돌의 값을 최소화 or 최대화 하면 정답이 된다.
Source Code
All reactions