#P10889. 【烂题杯 Round 1】糖果色的梦
【烂题杯 Round 1】糖果色的梦
Problem Description
Little A had a candy-colored dream, so he decided to buy some candies for his children.
Little A can buy candies at retail, buy candies in bulk, and also recycle candies in bulk.
-
Retail purchase: Each time, Little A can buy one candy for one child, which costs yuan.
-
Bulk purchase: Each time, Little A can buy one candy for each child among a consecutive segment of at least children. Let the number of children be ; this costs yuan.
-
Bulk recycling: Each time, Little A can take back one candy from each child among a consecutive segment of at least children, and he will earn yuan.
The -th child hopes to receive at least candies. Find the minimum cost for Little A to satisfy all children.
Input Format
The first line contains two positive integers and , representing the number of children and the minimum number of children required for a bulk operation.
Then two integers and are given.
The next line contains non-negative integers , representing the number of candies each child hopes to receive.
Output Format
Output one integer on one line, representing the minimum cost.
4 2
1 1
1 2 3 4
6
10 5
1 3
1 1 4 5 1 4 1 9 19 81
124
Hint
Explanation for Sample 1:
We bulk-buy candy for each child in , with cost . We bulk-buy candies for each child in , with cost . We buy candies separately for child , with cost . We buy candies separately for child , with cost . The total cost is .
Constraints:
For of the testdata, .
For of the testdata, the memory limit is at least 512 MB.
For of the testdata, , , , . The memory limit is at least 10 MB.
Translated by ChatGPT 5