Official algorithmic problem description and constraints.
You are given an integer array π of length π.
You can perform the following operation: choose an element of the array and replace it with any of its neighbor's value.
For example, if π=[3,1,2], you can get one of the arrays [3,3,2], [3,2,2] and [1,1,2] using one operation, but not [2,1,2 or [3,4,2].
Your task is to calculate the minimum possible total sum of the array if you can perform the aforementioned operation at most π times.
Detailed video explanations, mathematical intuition, and clean C++ implementation code.