DOJ logoDOJ
Problems
Recently added problemsSaved problems
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-backed certification.

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

Lemon Melon Cookie

Back to problem

Editorial

The answer is impossible if more than NNN lemon cookies or more than NNN melon cookies are already fixed.

Otherwise, exactly N−#MN-\#MN−#M undecided positions must become melon cookies. Changing position iii from lemon to melon adds cost iii, so the earliest available positions should be chosen.

The time complexity is O(N)O(N)O(N) per test case and the extra space complexity is O(1)O(1)O(1).

Solution written by GPT5