Stones Distribution
Time limit1sMemory limit512 MB
Distribute exactly s stones among n stoves of capacity v to minimize the sum over compartments of k_i times the product of the two adjacent stove counts.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Greedy, Math, Implementation
- Solved
- No attempts yet
Problem
The Innopolis sports center has an amazingly well-equipped hi-tech sauna. However, because complex techniques were used to build it, people are not sure how to maintain it properly.
The sauna has consecutive compartments. Between each pair of adjacent compartments there is a stove. There are two more stoves: one connected only to the first compartment, and one connected only to the last, so there are exactly stoves in total.
The -th compartment has volume . Each stove can hold from 0 to stones. Let be the number of stones in the -th stove. Then the -th compartment receives units of heat.
The sports center has stones for the stoves. The management wants to minimize the sum of heat received by all compartments so that the rest of the building does not get heated, but every stone must be used because buying them was a waste otherwise. Help the management solve this problem.
Input
The first line contains three integers , , and : the number of stoves, the number of stones, and the stove capacity (, , ).
The second line contains integers , the volume of the -th compartment ().
Output
Print the minimum possible total heat received by all compartments.
Hint
The correct answer for the sample is achieved by putting four stones in the first and the last stove and two stones in the second. Then the heat in every compartment except the second is 0, and the heat in the second compartment is .