← CSES Better

Adjust Pillars into a Consecutive Sequence

ZIO · 2024 · Zonal Informatics Olympiad · P2

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

arrays · optimization · dynamic-programming

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

sequence

Choose a consecutive target band

A beautiful sequence has one shared starting height; each next target rises by one.

State table
IndexOriginal heightTarget height
iH_ix+i
all iH_i >= 1min sum |H_i-(x+i)|
  1. 1

    Pick a start

    For a target beginning at x, position i must become x + i.
  2. 2

    Compare costs

    For each position, count additions or legal removals needed to reach its target; heights cannot fall below one.
  3. 3

    Take the least

    The answer is the minimum total adjustment cost over valid starting heights.
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.