---
id: 1920
lang: en
translation_of: index.md
source_sha256: 73a4d0187162a4ceeaf3c87218a47962377ab8dd02642c59382fc437f245adf9
title: "Extended Min-Max Inversion"
description: "Deriving the inclusion–exclusion coefficients that extend min-max inversion from the maximum to the k-th largest value, using binomial inversion."
tags: []
translated: 2026-11-27
translator: Claude Opus 5.5
translator_model: claude-opus-5-5
translation_notes:
  - "The Chinese title is bilingual (扩展最值反演｜Extended Min-Max Inversion), both halves saying the same thing; the English title keeps just the author's own English half."
  - "重返现世 (P4707) rendered as “Return to the Real World”; the pun 毒瘤现世 follows it as “Return to the Nasty World”."
  - "The post ends abruptly after the first sentence of the example section, as in the original."
---

## 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.

<!--more-->

## 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

<span class="slang" data-zh="毒瘤现世" data-gloss="dúliú xiànshì, a pun on the problem title 重返现世, swapping in 毒瘤 (dúliú, “tumor”), slang for a painfully hard, tedious problem.">Return to the Nasty World</span>. First of all, this problem is really just asking you for the expected value of the $n - k + 1$-th largest element.
