← CSES Better

Milk Exchange

USACO · 2024 · February · gold-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

prefix-sums · simulation

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

sample trace

Milk Exchange: prefix sums walkthrough

Milk Exchange: use the linked editorial?s prefix sums, simulation idea on the published sample, then verify the displayed output.

Published input6 2 2 2 1 2 1 8 3 8 6 4 8 3 8 1 10 9 9 10 10 6 8 2 1000000000 1000000000 1000000000modelAlgorithm ideaStore cumulative aggregates so a range can be answered from two prefix values instead of rescanning its elements.task resultExpected output8 7 6 6 6 6 25 20 17 14 12 10 8 8 2000000053 1000000054 56 49 42 35 28 24 20 20
  1. 1

    Accumulate

    Build the running total or count across the input order.
  2. 2

    Query

    Subtract the prefix before a range from the prefix at its end.
  3. 3

    Finish

    Apply the task?s boundary adjustment and compare with the sample result.
  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.