DOJ logoDOJ
Problems
Recently added problemsSaved problemsWorkbooks
CategoriesDLCContestsGroupsTeamsBoard
Ranking
Solved Problem RankingStreak rankingDOJ Power ranking
Status
Call for TasksLoginRegister
DOJ logoDOJ

Community online judge with OI-style subtask scoring, Elo ratings, and Discord account linking.

Problems
ProblemsCategories
Community
ContestsRankingBoardNoticesHost an external contestGuide
Account
LoginRegisterJudge Status
Policy
Terms of ServiceDLC RulesPrivacyAPI documentationLanguage runtimesContest rank rewardsRating and performance
© 2026 DOJ
All rights reserved
Editorial

Mochi

Back to problem

Editorial

Let FFF be the maximum frequency of any size. Each bundle needs two rice cakes of different sizes.

If some size appears more than N/2N/2N/2 times, each rice cake of that size must be paired with a rice cake of another size, so at most N−FN-FN−F bundles are possible. If F≤N/2F\leq N/2F≤N/2, the most frequent size can be paired with the remaining cakes and ⌊N/2⌋\lfloor N/2\rfloor⌊N/2⌋ bundles can be formed.

Hence the answer is min⁡(⌊N/2⌋,N−F)\min(\lfloor N/2\rfloor,N-F)min(⌊N/2⌋,N−F). Counting frequencies with a hash table takes expected O(N)O(N)O(N) time. Solution written by GPT5.6