Skip to content

Chapter 13 — Worked Solutions

This chapter doesn't teach you algorithms. It teaches you how to think about problems — from the moment you read the statement to the moment you hit Submit. Each file is a full thinking transcript: wrong turns included, insights explained, implementation gotchas highlighted.

These aren't editorials. Editorials tell you the answer. These show you the process of finding it.

Coming from: Chapter 12 — Practice Ladders — structured practice from CF 1100 to 2100
Going to: Chapter 14 — Problem Reduction — the meta-skill of transforming unfamiliar problems into familiar ones

Solutions by Technique

The "thinking pattern" column is the transferable move — the reframing or invariant that unlocks the problem. The technique column is the tool that follows once the reframing is in place.

#ProblemThinking patternCore techniqueRatingFile
01CF 1691D — Max GEQ Sumfix the element controlling the maxmonotonic stack + sparse table180001-max-geq-sum.md
02CF 1474C — Array Destructionforced largest-element choicegreedy with multiset peel170002-array-destruction.md
03CF 1354D — Multisetbounded values beat ordered setsbinary search on BIT190003-multiset.md
04CF 1175E — Minimal Segment Coverjump structure on intervalsbinary lifting200004-minimal-segment-cover.md
05CF 1559D2 — Mocha and Diana (Hard)hub through node 1, then pair across foreststwo DSUs190005-mocha-and-diana.md
06CF 1536D — Omkar and Medianscheck feasibility, do not constructinvariant on a sorted set170006-omkar-and-medians.md
07CF 1385E — Directing Edgesorient along a topo order of the directed parttoposort certificate170007-directing-edges.md
08CF 1538F — Interesting Functioncount each digit position independentlyper-place arithmetic180008-interesting-function.md
09CF 1443D — Extreme Subtractionswitch to the difference arraymonotone decomposition180009-extreme-subtraction.md
10CF 1498C — Planar Reflectionsstate = (mirror, remaining bounces, direction)DP after collapsing symmetry160010-planar-reflections.md

How to Use These

These files are deliberate practice, not passive reading. To extract the most:

  1. Try the problem first. Spend at least 20 minutes on the original statement before opening the file.
  2. Pause after the "First Read" section. Write down — out loud or on paper — what you would try first and why. Predict the wrong turn before the file shows it.
  3. Read forward only after committing. Compare each step in the transcript against your written hypothesis. Where did your thinking diverge, and at what cost?
  4. Extract the thinking pattern. Add the one-line reframing from the table to your mental pattern library. The technique is replaceable; the reframing is what transfers.

If you read the file like a normal editorial, you get the answer but not the training. The pause matters.

Built for the climb from Codeforces 1100 to 2100.