← CSES Better

ZCO 2019 - 2 UpDown Sequences

ZCO · 2019 · Zonal Computing Olympiad · UPDOWSEQ

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 · greedy · sequence

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

alternating peaks

The target pattern alternates valleys and peaks

An UpDown segment has low positions between high positions; one inserted value may bridge a broken comparison pattern.

a1 <= a2a2 >= a3a3 <= a4
  1. 1

    Track zigzag runs

    Scan the sequence while tracking the longest alternating run ending in each comparison direction.
  2. 2

    Bridge one insertion

    At the one insertion point, test how neighboring values can satisfy both sides of the zigzag.
  3. 3

    Keep the longest run

    Keep the longest valid resulting subsegment.
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.