← CSES Better

Brackets

INOI · 2016 · Indian National Olympiad in Informatics · INOI1602

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

brackets · stack · parsing

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

typed bracket stack

A closing token must match the most recent opener

Choose a subsequence of values whose corresponding typed brackets form a well-bracketed sequence, maximizing the sum.

open type t -> pushclose type t -> match topempty stack -> balanced
  1. 1

    Choose or skip positions

    A selected bracket position contributes its value; unselected positions disappear.
  2. 2

    Maintain valid nesting

    Opening and closing bracket types must match in properly nested order.
  3. 3

    Maximize selected values

    Among all well-bracketed subsequences, keep the greatest sum, including negative values correctly.
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.