Manny has just been hired to build a house! Manny's first problem to begin with was the…
- User
Manny has just been hired to build a house! Manny's first problem to begin with was the flatness of the ground under the house. More precisely, the ground under the house was in the form of a table of infinite right, which is the height of the column i It's 1st (from the left) h i h i is As in the following example: (dots in the table indicate that the table is continuous and infinite from the right side, for example h 3
5 h 3 =5 and h 7
0 h 7 =0)
Sample shape
To smooth the surface, Mani can use a combination of these two operations:
A house adds soil to a pillar and a to pay Start with the bulldozer from the top of the leftmost column and go to the right. If the height of the next column is higher than the column it is in, the soil of that column will be pushed to the next column, and if the height of the next column is lower than the current column, it will stop. Also the total cost of this operation b b is the unit. (For more details, pay attention to example 1.) Note that the goal is to level the columns that have at least one soil unit. In other words, at the end, the height of all columns that have at least one unit of soil must be equal. Now help Mani to level the ground with the least cost.
input In the first line of the input respectively n n, a a and b b is given. 1 ≤ n ≤ 2000 1≤n≤2000 1 ≤ a , b ≤ 1 0 9 1≤a,b≤10 9
In the second input line n n is a number that i Their i-th is equal to the height of the column i iam or the same h i h i is 1 ≤ h i ≤ 2000 1≤h i ≤2000 Note for i
n i>n amount h i h i is equal to zero.
output Print the minimum cost on the only output line.
Example Sample entry 1 4 7 9 2 4 3 1 Plain text Sample output 1 9 Plain text You can get the answer by performing operation 2 once. In this example n
4 n=4 is Note that soil can enter houses after n n the first column also reach the first stage, the second stage, the third stage, the fourth stage
Sample input 2 6 1 3 3 2 5 1 4 4 Plain text Sample output 2 5 Plain text The example is related to the first form of the question, which can be performed in the following order:
Add a dirt house to the second column and pay 1 unit. Perform type 2 operation once and pay 3 units. Add a dirt house to the seventh column and pay 1 unit. In the end, the total costs of this example will be equal to 1+3+1=5.
Sample entry 3 1 5 6 10 Plain text Sample output 3 0 Plain text In this example there is only one column and the ground is flat from the start. write in c++
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.