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

TLE

Back to problem

Editorial

Let P=max⁡({ti:ci=0}∪{0})P=\max(\{t_i:c_i=0\}\cup\{0\})P=max({ti​:ci​=0}∪{0}) and Q=min⁡({ti:ci=1}∪{109+1})Q=\min(\{t_i:c_i=1\}\cup\{10^9+1\})Q=min({ti​:ci​=1. We need P≤T<QP\leq T<QP≤T<Q and T>0T>0T>0, equivalent to P<QP<QP<Q. Choose T=PT=PT=P if P>0P>0P>0, otherwise T=0.5T=0.5T=0.5 milliseconds. Time is O(N)O(N)O(N) and auxiliary space O(1)O(1)O(1). A naive solution sorts by time, checks that equal times have equal labels, and forbids a 0 after a 1. It passes in O(Nlog⁡N)O(N\log N)O(NlogN).

Solution written by GPT6

}
∪
{109+
1})