#P16289. [蓝桥杯 2026 省 Python A 组] 购电优化
[蓝桥杯 2026 省 Python A 组] 购电优化
Problem Description
A data center needs to complete a series of computing tasks in the next time periods, so it must plan an electricity purchasing strategy in advance to reduce the total cost as much as possible.
Specifically, the -th time period requires units of electricity, and all of this electricity must be ready before the end of the -th time period. You may purchase electricity in any time period: if you buy electricity in the -th time period, then the price is 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 . 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 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 and cannot be below .
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 and , representing the number of time periods and the capacity of the energy storage battery.
The second line contains non-negative integers , where denotes the electricity required in the -th time period.
The third line contains non-negative integers , where denotes the price per unit of electricity when purchasing in the -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 -st time period, buy units of electricity, costing yuan; use unit immediately, and store the other unit in the battery.
- In the -nd time period, buy units of electricity, costing yuan; all units are used to meet the demand of the current time period.
- In the -rd time period, directly use the remaining unit of electricity in the battery, with no additional purchase.
Therefore, the total cost is yuan.
Constraints
For of the testdata, , .
For of the testdata, , .
For another of the testdata, , and .
For another of the testdata, .
For of the testdata, , , .
Translated by ChatGPT 5