Official

C - Solutions Editorial by evima


The problem \(P\) is called the interval scheduling problem, and it is known that the greedy algorithm represented by Takahashi’s program finds the optimal solution.

If \(M < 0\):

As mentioned above, Takahashi’s program prints the optimal solution, so this is never the case.

If \(M = N\):

The value printed by Aoki’s program is always \(1\) or greater, so this is never the case.

If \(M = N - 1\) and \(N \geq 2\):

The value printed by Aoki’s program is always \(1\) or greater, so in order for \(M = N - 1\) to hold, Takahashi’s and Aoki’s programs must print \(N\) and \(1\), respectively. However, in an input where Takahashi’s program prints \(N\), no two intervals intersect, so Aoki’s program also prints \(N\), making the input not a solution for \(N \geq 2\).

If \(M = 0\):

If we place all intervals so that no two of them intersect, the condition will be satisfied.

If none of the above holds, that is, if \(1 \leq M \leq N - 2\):

Let us choose one large interval and place \(M + 1\) intervals inside it so that no two of them intersects. Then, if we place the remaining \(N - M - 2\) intervals so that they do not intersect the other intervals, the condition will be satisfied.

posted:
last update: