Gale-Ryser Theorem

Правка en5, от Noobish_Monk, 2026-01-19 17:14:46

Hi everyone!

Today I want to write about the Gale-Ryser Theorem and some of its applications.

Gale-Ryser Theorem

We have an array of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$ and $$$m$$$ positive integers $$$b_1, b_2, \ldots, b_m$$$ up to $$$n$$$. The array $$$b$$$ is a sequence of operations, in $$$i$$$-th operation we need to decrease $$$b_i$$$ positions by $$$1$$$, formally pick $$$b_i$$$ unique indices $$$j_1, j_2, \ldots, j_{b_i}$$$ and decrease $$$a_{j_p}$$$ by $$$1$$$ for $$$1 \le p \le b_i$$$. We want to know if it's possible to have all $$$a_i \ge 0$$$ after the operations.

Without loss of generality $$$b_1 \ge b_2 \ldots \ge b_m$$$. The Theorem says that it's possible iff $$$\sum \limits_{i=1}^k \min(a_i, k) \ge \sum \limits_{j=1}^k b_j$$$ for $$$\forall 1 \le k \le m$$$.

Necessity
Sufficiency

Proof by induction also suggests a strategy for the construction, which turns out to be the first greedy that comes to mind — always selecting $$$b_i$$$ maximum positions. Now you know the proof behind this greedy. While it doesn't follow from this proof, it's actually not needed to sort $$$b$$$ to run the greedy. Later in the blog it will also be proven, but for now just remember that we can pick maximum positions in any order we want.

An important special case, all $$$b_i = t$$$. That is, $$$m$$$ times $$$t$$$ positions are decreased. Then it is only needed to check that $$$\sum \limits_{i=1}^n \min(t, a_i) \ge mt$$$

Proof

Another example is 1774B - Coloring. Statement: we have $$$n$$$ cells and $$$m$$$ colors, each cell must be colored. For each color there must be exactly $$$a_i$$$ cells painted with that color ($$$\sum a = n$$$). Also, every window of given size $$$k$$$ can't have cells of one color.

Solution (yes, editorial for div2B

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en25 Английский Noobish_Monk 2026-02-16 21:28:14 19 Tiny change: '/6339)\n\n---\n\' -> '/6339)\n\n[problem:1740F]\n\n---\n\'
en24 Английский Noobish_Monk 2026-02-10 15:28:01 0 (published)
en23 Английский Noobish_Monk 2026-02-10 15:27:20 1
en22 Английский Noobish_Monk 2026-02-10 15:27:11 102
en21 Английский Noobish_Monk 2026-02-10 15:25:51 83 Tiny change: 'tCoder ABC which uses the Theorem](https://' -> 'tCoder ABC](https://'
en20 Английский Noobish_Monk 2026-02-10 15:21:51 430 Tiny change: 'm from JOI](https://' -> 'm from JOISC 2023](https://'
en19 Английский Noobish_Monk 2026-02-10 02:33:38 9130 Tiny change: '+ k_2 \ge x$, then:\' -> '+ k_2 \ge c_x$, then:\'
en18 Английский Noobish_Monk 2026-02-08 15:50:16 361 Tiny change: '1893D]\n\nDual\n' -> '1893D]\n\n---\n\nDual\n'
en17 Английский Noobish_Monk 2026-01-28 23:58:37 393
en16 Английский Noobish_Monk 2026-01-28 03:41:24 2700 Tiny change: 'reases $x - 1$.\n\n![' -> 'reases $x + 1$.\n\n!['
en15 Английский Noobish_Monk 2026-01-27 21:30:10 553 Tiny change: 'Hi everyon' -> 'Your title here...\n==================\n==================Hi everyon'
en14 Английский Noobish_Monk 2026-01-22 14:59:31 4
en13 Английский Noobish_Monk 2026-01-22 14:58:20 2
en12 Английский Noobish_Monk 2026-01-22 14:57:20 835
en11 Английский Noobish_Monk 2026-01-22 14:29:26 2760 Tiny change: '+ a_2$\n\n...\n\n$k = t' -> '+ a_2$\n\n$\ldots$\n\n$k = t'
en10 Английский Noobish_Monk 2026-01-21 02:04:54 402
en9 Английский Noobish_Monk 2026-01-20 21:49:06 353 Tiny change: 'we can add$m — k$ minimu' -> 'we can add $m - k$ minimu'
en8 Английский Noobish_Monk 2026-01-19 20:09:57 803 Tiny change: 'g m \cdot (time to get count and sum))$' -> 'g m \cdot $(time to get certain sum)$)$'
en7 Английский Noobish_Monk 2026-01-19 19:37:06 1773 Tiny change: 'k = 1 \Rigtharrow m \g' -> 'k = 1 \Rightarrow m \g'
en6 Английский Noobish_Monk 2026-01-19 17:16:29 3 Tiny change: ' for div2B">\nFor ea' -> ' for div2B)">\nFor ea'
en5 Английский Noobish_Monk 2026-01-19 17:14:46 2624 Tiny change: 'oiler>\n\n' -> 'oiler>\n\n\n=================='
en4 Английский Noobish_Monk 2026-01-19 16:00:44 1269 Tiny change: 'er an $S\\T$ cut. Sp' -> 'er an $S\\ T$ cut. Sp'
en3 Английский Noobish_Monk 2026-01-19 14:52:31 1831 Tiny change: 'oiler>\n\n' -> 'oiler>\n\n<spoiler summary="Sufficiency">\n...\n</spoiler>'
en2 Английский Noobish_Monk 2026-01-19 14:32:50 568 Tiny change: '_j$ for $\all 1 \le ' -> '_j$ for $\forall 1 \le '
en1 Английский Noobish_Monk 2026-01-19 14:21:30 592 Initial revision (saved to drafts)