NOI Contest Archive

Archive / 2024 / April 2024

Pixel Paint

Medium · NOI 2024 April Monthly Contest

You’re given a canvas grid with \(n*10^{9}\) pixels. (\(n\) columns with \(10^{9}\) pixels) Each column has a continous set of pixels painted starting from the bottom with height \(h_i\) (\(1 \leq i \leq n\)).

You’re allowed to paint new pixels and erase already painted pixels. The cost to either paint or erase a pixel in column \(i\) is \(h_i \text{ mod } 97\). Where \(h_i\) is the initial height.

Your goal is to find the minimum cost to make all columns the same height.

Input Format

Output Format

Constraints

Subtask 1: 10 points

Subtask 2: 30 points

Subtask 3: 60 points

Sample Input 0

3
1 2 3

Sample Output 0

4