#P10889. 【烂题杯 Round 1】糖果色的梦

    ID: 12319 远端评测题 1000ms 10~512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>网络流O2优化费用流线性规划

【烂题杯 Round 1】糖果色的梦

Problem Description

Little A had a candy-colored dream, so he decided to buy some candies for his nn 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 11 yuan.

  • Bulk purchase: Each time, Little A can buy one candy for each child among a consecutive segment of at least kk children. Let the number of children be ll; this costs (lB)(l - B) yuan.

  • Bulk recycling: Each time, Little A can take back one candy from each child among a consecutive segment of at least kk children, and he will earn CC yuan.

The ii-th child hopes to receive at least aia_i candies. Find the minimum cost for Little A to satisfy all children.

Input Format

The first line contains two positive integers nn and kk, representing the number of children and the minimum number of children required for a bulk operation.

Then two integers BB and CC are given.

The next line contains nn non-negative integers a1,a2,,ana_1, a_2, \cdots, a_n, 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 11 candy for each child in [1,2][1,2], with cost 11. We bulk-buy 33 candies for each child in [3,4][3,4], with cost 33. We buy candies separately for child 22, with cost 11. We buy candies separately for child 44, with cost 11. The total cost is 66.

Constraints:

For 20%20\% of the testdata, 1kn101 \le k \le n \le 10.

For 40%40\% of the testdata, the memory limit is at least 512 MB.

For 100%100\% of the testdata, 1kn10001 \le k \le n \le 1000, 0Bk0 \le B \le k, 0CkB0 \le C \le k - B, 0ai1090 \le a_i \le 10^9. The memory limit is at least 10 MB.

Translated by ChatGPT 5