Extended Min-Max Inversion
Quick Start
First, you need to learn min-max inversion and binomial inversion. The formulas are as follows:
\[ \begin{gathered} \max(S) = \sum_{T \subset S} (-1)^{|T| - 1} \min(T) \\ f_i = \sum_{j = 0}^i {i \choose j} g_j \Leftrightarrow g_i = \sum_{j = 0}^i (-1)^{i - j} {i \choose j} f_j \end{gathered} \]
Then, you need a certain understanding of inversion and inclusion–exclusion, enough to understand what the inclusion–exclusion coefficients mean.
Introduction and Derivation
Extended min-max inversion is really just finding the \(k\)-th largest value by doing inclusion–exclusion over minimums. The formula is as follows:
\[ \text{kthmax}(S) = \sum_{T \subset S} (-1)^{|T| - 1} {|T| - 1 \choose k - 1} \min(T) \]
So how do we get an inclusion–exclusion coefficient like \((-1)^{|T| - 1} {|T| - 1 \choose k - 1}\)? Let's derive it. Set the inclusion–exclusion coefficient to \(c_i\), and the original formula becomes:
\[ \text{kthmax}(S) = \sum_{T \subset S} c_{|T|} \min(T) \]
Now let's think about the condition \(c_i\) has to satisfy. When \(\min(T)\) is the \(i\)-th largest number, we want \(c_i\) to satisfy:
\[ \sum_{j = 0}^{i - 1} {i - 1 \choose j} c_{j + 1} = [i = k] \]
You can picture it as: after fixing the \(i\)-th largest, among the \(i - 1\) enumerate \(|T|\)’s size \(j\), choose \(j\) elements and multiply by \(c_j\), and that should equal the number of times we expect it to be counted. Let's shift the indices and then do binomial inversion:
\[ \begin{aligned} c'_i &= c_{i + 1}, \sum_{j = 0}^{i} {i \choose j} c'_j = [i = k - 1] \\ c'_i &= \sum_{j = 0}^i (-1)^{i - j} {i \choose j} [j = k - 1] = (-1)^{i - k + 1} {i \choose k - 1} \\ c_i &= (-1)^{i - k} {i - 1 \choose k - 1} \end{aligned} \\ \]
Done deriving.
Example: P4707 Return to the Real World
Return to the Nasty World. First of all, this problem is really just asking you for the expected value of the \(n - k + 1\)-th largest element.