← CSES Better

Splitting Haybales

USACO · 2024 · US Open · platinum-2

Open official problem ↗
Ask AI

Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.

Open Claude Desktop

binary-search · trees · sorting · data-structures · simulation

The organizer’s problem statement is available at the official source link.

sample trace

Splitting Haybales: binary search walkthrough

Splitting Haybales: use the linked editorial?s binary search, trees idea on the published sample, then verify the displayed output.

Published input2 3 1 15 1 1 -2 1 1 -1 1 1 0 1 1 1 1 1 2 1 2 -2 1 2 -1 1 2 0 1 2 1 1 2 2 2 2 -2 2 2 -1 2 2 0 2 2 1 2 2 2 5 4 4 3 1 1 7 1 1 20 1 2 20 1 5 20 1 1 0 1 5 0 1 4 0 3 5 2modelAlgorithm ideaSearch a monotone boundary by repeatedly testing a midpoint with the editorial?s feasibility condition.task resultExpected output1 2 3 -2 -1 0 1 2 -1 0 -1 0 1 0 1 16 12 7 4 1 2 1
  1. 1

    Range

    Set the candidate interval for the quantity the task asks to minimize or maximize.
  2. 2

    Test

    Evaluate the task?s feasibility condition at the midpoint.
  3. 3

    Narrow

    Keep the half containing the true boundary until the answer is determined.
  4. 4

    Verify the sample

    Use the published sample output to check the result of this idea on the displayed input.
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|12 lines, 156 chars

Run output

Run your code to see output.