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

Streaming Channels

Back to problem

Editorial

Let the maximum streaming duration of one channel be LLL.

First, fix the ending time of the streaming interval as ttt. The earliest possible starting time is max⁡(0,t−L)\max(0,t-L)max(0,t−L), so for a fixed ttt it is always optimal to use the interval [max⁡(0,t−L),t][\max(0,t-L),t][max(0,t−L),t]. Session iii is contained in this interval if and only if

Ei≤t≤Si+L.E_i \leq t \leq S_i+L.Ei​≤t≤Si​+L.

Thus session iii adds 111 to the range [Ei,Si+L][E_i,S_i+L][Ei​,Si​+ of possible ending times.

Conversely, if the starting time is fixed as ttt, the latest possible ending time is t+Lt+Lt+L. Session iii is contained if and only if

max⁡(0,Ei−L)≤t≤Si.\max(0,E_i-L) \leq t \leq S_i.max(0,Ei​−L)≤t≤Si

Thus session iii adds 111 to the range [max⁡(0,Ei−L),Si][\max(0,E_i-L),S_i][max(0,Ei​−L), of possible starting times.

Using sweep-line range-add events, for each LLL we compute two functions.

  • PL(T)P_L(T)PL​(T): the maximum number of sessions streamed by one interval whose ending time is at most TTT.
  • QL(T)Q_L(T)QL​: the maximum number of sessions streamed by one interval whose starting time is at least .

If channel A is operated before channel B, there is a boundary time TTT such that the first interval ends at or before TTT and the second interval starts at or after TTT. The best value for this order is

max⁡T(PLA(T)+QLB(T)).\max_T \left(P_{L_A}(T)+Q_{L_B}(T)\right).Tmax​(PLA​​

The opposite order is handled similarly by computing max⁡T(PLB(T)+QLA(T))\max_T(P_{L_B}(T)+Q_{L_A}(T))maxT​(PLB​​(T.

The values of these functions change only at event times. Therefore, it is enough to evaluate the formulas at the sorted union of their event times.

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

Solution written by GPT5.5

L]
​
.
S
i​
]
(
T
)
TTT
(
T
)
+
QLB​​
(
T
)
)
.
)
+
QLA​​(T))