Minimum cost increasing sequence
Time limit2sMemory limit512 MB
Transform A into a strictly increasing integer sequence B minimizing the sum of |B_i - A_i|, and output the lexicographically smallest such B.
- Level
Hard9 of 10
- Topics
- Dynamic programming, Greedy, Heap
- Solved
- No attempts yet
Problem
You are given an integer sequence of length .
Among the integer sequences that satisfy , find one that minimizes . Every element of fits in a signed 32-bit integer.
Several sequences can reach the minimum sum. Print the lexicographically smallest one, so make as small as possible, then fix that value and make as small as possible, and continue in the same way.
Input
The first line contains . ()
The second line contains separated by spaces. ()
Output
Print the lexicographically smallest optimal sequence on lines, one element per line.
Hint
For the minimum sum is . More than one reaches it, and also has sum . The lexicographically smallest one is .