#P16289. [蓝桥杯 2026 省 Python A 组] 购电优化

    ID: 18304 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 显示难度提高 上传者: 标签>贪心单调队列2026蓝桥杯省赛

[蓝桥杯 2026 省 Python A 组] 购电优化

Problem Description

A data center needs to complete a series of computing tasks in the next nn time periods, so it must plan an electricity purchasing strategy in advance to reduce the total cost as much as possible.

Specifically, the ii-th time period requires wiw_i units of electricity, and all of this electricity must be ready before the end of the ii-th time period. You may purchase electricity in any time period: if you buy electricity in the ii-th time period, then the price is cic_i yuan per unit.

However, electricity prices may differ a lot between time periods. To make better use of this, the data center is equipped with an energy storage battery with capacity kk. With this battery, you can buy more electricity during cheaper periods and store it, then use it later during more expensive periods or when electricity is needed, thus reducing the overall spending.

The battery starts with 00 units of electricity, and losses during charging and discharging can be ignored. Also, at any time, the amount of electricity in the battery cannot exceed the capacity kk and cannot be below 00.

Now, please compute the minimum amount of money (in yuan) that must be spent to purchase electricity, while ensuring that the electricity demand of every time period can be satisfied.

Input Format

The input consists of 3 lines.

The first line contains two integers nn and kk, representing the number of time periods and the capacity of the energy storage battery.

The second line contains nn non-negative integers w1,w2,…,wnw_1, w_2, \dots, w_n, where wiw_i denotes the electricity required in the ii-th time period.

The third line contains nn non-negative integers c1,c2,…,cnc_1, c_2, \dots, c_n, where cic_i denotes the price per unit of electricity when purchasing in the ii-th time period.

Output Format

Output one line with one non-negative integer, representing the minimum electricity purchase cost required to meet the demand of all time periods.

3 1
1 2 1
20 25 100
90

Hint

Sample Explanation

The optimal plan is as follows:

  • In the 11-st time period, buy 22 units of electricity, costing 2×20=402 \times 20 = 40 yuan; use 11 unit immediately, and store the other 11 unit in the battery.
  • In the 22-nd time period, buy 22 units of electricity, costing 2×25=502 \times 25 = 50 yuan; all 22 units are used to meet the demand of the current time period.
  • In the 33-rd time period, directly use the remaining 11 unit of electricity in the battery, with no additional purchase.

Therefore, the total cost is 40+50=9040 + 50 = 90 yuan.

Constraints

For 20%20\% of the testdata, n≤10n \leq 10, k≤10k \leq 10.

For 40%40\% of the testdata, n≤500n \leq 500, k≤1000k \leq 1000.

For another 20%20\% of the testdata, n≤3000n \leq 3000, and ∑wi≤106\sum w_i \leq 10^6.

For another 10%10\% of the testdata, k≤100k \leq 100.

For 100%100\% of the testdata, 1≤n≤5×1051 \leq n \leq 5 \times 10^5, 0≤k≤1090 \leq k \leq 10^9, 0≤wi,ci≤1090 \leq w_i, c_i \leq 10^9.

Translated by ChatGPT 5