#P1934. 封印
封印
Description
The seal of the Well of Gods and Demons has layers, and each layer has a sturdiness value. When Long Ming, a demon, breaks a single layer alone, the energy consumed equals the product of that layer’s sturdiness and the square of the total number of layers . He can also break all seals from layer to layer (with ). The total energy consumed equals the product of the sum of the sturdiness of layers and and the sum of the sturdiness of all layers from to inclusive. However, to avoid alarming Shu Mountain, the sum of the sturdiness of layers and must not exceed (this restriction does not apply when breaking a single layer).
Input Format
The first line contains two positive integers and .
The second line contains positive integers, where the ‑th number is , representing the sturdiness of layer .
Output Format
Output a single line containing one positive integer, the minimum energy consumed.
6 10
8 5 7 9 3 5
578
Hint
Sample Explanation
First break the first layer alone, then use the Traverse Technique to break directly from the second layer to the last layer. The energy consumed is $8 \times 6^2 + (5 + 5) \times (5 + 7 + 9 + 3 + 5) = 578$.
Constraints
For of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号