#P4480. [BJWC2018] 餐巾计划问题
[BJWC2018] 餐巾计划问题
Description
A restaurant requires a varying number of napkins over consecutive days. Suppose on day () it needs napkins. The restaurant can purchase new napkins at any time, at a cost of per napkin. Used napkins must be washed before reuse. Sending one used napkin to laundry A returns it after days at a cost of ; sending one used napkin to laundry B returns it after days at a cost of . For example, a napkin used on day and sent to laundry A can be used on day .
Arrange the napkin usage plan over days to minimize the total cost.
Input Format
The first line contains six positive integers .
The next lines each contain a positive integer .
Output Format
Output one line containing a single positive integer, the minimum total cost.
4 1 2 2 1 3
8
2
1
6
35
Hint
【Sample Explanation】
Day 1: Buy 8 napkins, costing 24. Send 2 napkins to laundry A and 6 napkins to laundry B.
Day 2: Take back 2 napkins from laundry A, costing 4. Send 1 napkin to laundry B.
Day 3: Take back 6 napkins from laundry B, costing 6.
Day 4: Take back 1 napkin from laundry B, costing 1. This achieves the minimum cost.
【Constraints】
For 30% of the testdata, , , .
For 50% of the testdata, , .
For 70% of the testdata, .
For 100% of the testdata, , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号