Longest Affordable Window
Maintain a contiguous budget window under nonnegative costs.
Adult planning suggestion: about 9–12 · Logic & rule checking
- Players
- 2–4; cooperate, then exchange the checker role
- Time
- 15–25 minutes
- Materials
- Paper, pencil and the supplied player sheet; keep the host sheet separate.
Prepare
Place costs 2,1,1,1,4,1,1 in this fixed order. Budget is 5. Use two paper pointers and a running-sum record; costs are nonnegative and may not be reordered.
Follow the rule
Find the longest contiguous block whose total is at most 5. Extend the right pointer one position. While over budget, remove the leftmost included cost and advance the left pointer.
Check each step
Write each valid window length after shrinking. Removing a nonnegative cost cannot increase the sum; this is why the left pointer need not move backwards. Do not choose scattered cheap items.
Worked example
The first four costs total 5. When the 4 arrives, shrink until only that 4 remains, then continue to the following costs. Compare all recorded valid window lengths.
Finish and adapt
Finish with the greatest length and its endpoints, then verify by enumerating all intervals. Negative costs are outside this activity: they invalidate the simple monotone argument.
Purpose, observation and provenance
Within this activity: Maintain a contiguous budget window under nonnegative costs.
Ask the checker to name a particular rule and show the recorded evidence. Speed alone is not the goal.
Our rules, examples and printable diagrams are separately prepared. The earliest inventor of the broader mechanism is not established here.
USACO Guide · Sliding Window — Mechanism background only. Our small paper instance and role rotation are separate; no endorsement or unique-solution claim.
Secondary practice: Cooperation and explaining a check.
For a class of 30, use ten groups of three. Prepare one player-material set per group and keep the host key with the adult. Rotate operator, recorder and checker after each worked example; a reader or scribe may help without choosing answers. Avoid public ranking or diagnostic labels.
Age bands are planning suggestions. Background references may address older learners and do not validate suitability for this age band. Goals describe observable actions, not measured long-term gains or institutional endorsement.
Free alternative: Copy the supplied grids, labels and cards onto reused paper. No specialist product is needed. Adults may prepare pieces or act as a scribe.
Printable materials
Preview at 100% scale, with browser headers and footers off. Cut with suitable help. Keep host keys separate. This is a manual tabletop kit, not an online opponent, automatic judge or solver.
Longest Affordable Window · Player materials
Place costs 2,1,1,1,4,1,1 in this fixed order. Budget is 5. Use two paper pointers and a running-sum record; costs are nonnegative and may not be reordered.
Find the longest contiguous block whose total is at most 5. Extend the right pointer one position. While over budget, remove the leftmost included cost and advance the left pointer.
Write each valid window length after shrinking. Removing a nonnegative cost cannot increase the sum; this is why the left pointer need not move backwards. Do not choose scattered cheap items.
| Index / 位 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|
| Cost / 费 | 2 | 1 | 1 | 1 | 4 | 1 | 1 |
| Step / cell | Decision / value | Rule checked |
|---|---|---|
| ________ | ________ | ________ |
| ________ | ________ | ________ |
| ________ | ________ | ________ |
| ________ | ________ | ________ |
Longest Affordable Window · Host key — keep separate
Maximum length 4, interval 1–4, sum 5. No length-5 interval fits: sums are 9,8,8. This is contiguous selection, not arbitrary-subset knapsack.
Lead and check
Place costs 2,1,1,1,4,1,1 in this fixed order. Budget is 5. Use two paper pointers and a running-sum record; costs are nonnegative and may not be reordered.
Find the longest contiguous block whose total is at most 5. Extend the right pointer one position. While over budget, remove the leftmost included cost and advance the left pointer.
Write each valid window length after shrinking. Removing a nonnegative cost cannot increase the sum; this is why the left pointer need not move backwards. Do not choose scattered cheap items.
The first four costs total 5. When the 4 arrives, shrink until only that 4 remains, then continue to the following costs. Compare all recorded valid window lengths.
Finish with the greatest length and its endpoints, then verify by enumerating all intervals. Negative costs are outside this activity: they invalidate the simple monotone argument.
Classroom: ten trios for 30 learners; one kit per trio. Rotate operator, recorder and checker. Age guidance is a planning suggestion; prerequisite support may be necessary.