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

Problem Numbers Aren't Sorted by Difficulty

Back to problem

Editorial

Map the tier names, from easiest to hardest, to 0,1,…,50,1,\ldots,50,1,…,5. If the mapped tier value is ggg, assign difficulty (g,d)(g,d)(g,d) the rank

r=5g+(5−d).r=5g+(5-d).r=5g+(5−d).

A smaller rank means an easier difficulty. This also correctly handles the reversed numeric direction within one tier name: level 555 is easier than level 111.

Let RRR be the rank of the threshold difficulty. Keep exactly the problems whose rank is at most RRR, then sort them by rank in increasing order. The relative order of problems with the same rank is irrelevant.

The reference implementation additionally sorts equal-difficulty problems by problem number, only to make its own output deterministic.

The time complexity is O(Nlog⁡N)O(N\log N)O(NlogN) per test case and the memory complexity is O(N)O(N)O(N).

Solution written by GPT5.6