Editorial
Let the maximum streaming duration of one channel be .
First, fix the ending time of the streaming interval as . The earliest possible starting time is , so for a fixed it is always optimal to use the interval . Session is contained in this interval if and only if
Thus session adds to the range of possible ending times.
Conversely, if the starting time is fixed as , the latest possible ending time is . Session is contained if and only if
Thus session adds to the range of possible starting times.
Using sweep-line range-add events, for each we compute two functions.
- : the maximum number of sessions streamed by one interval whose ending time is at most .
- : 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 such that the first interval ends at or before and the second interval starts at or after . The best value for this order is
The opposite order is handled similarly by computing .
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 and the memory usage is .
Solution written by GPT5.5