#P1251. 餐巾计划问题

    ID: 250 远端评测题 4000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>贪心网络流O2优化费用流网络流 24 题

餐巾计划问题

Description

A restaurant needs different numbers of napkins on NN consecutive days. Suppose on day ii it needs rir_i napkins (i=1,2,,Ni = 1, 2, \dots, N). The restaurant can buy new napkins at a cost of pp cents per napkin; or send used napkins to a fast laundry, which takes mm days and costs ff cents per napkin; or send them to a slow laundry, which takes nn days (n>mn \gt m) and costs ss cents per napkin (s<fs \lt f).

At the end of each day, the restaurant must decide how many dirty napkins to send to the fast laundry, how many to send to the slow laundry, and how many to store for later laundering. On each day, the total number of napkins returned from laundries that day plus newly purchased napkins must meet that day’s demand.

Design an algorithm to plan napkin usage over NN days so that the total cost is minimized. Write a program to find an optimal napkin usage plan.

Input Format

Input is given via standard input. The first line contains one positive integer NN, the number of days to plan.

The next line contains the restaurant’s napkin demand for each of the NN consecutive days.

The last line contains 55 positive integers p,m,f,n,sp, m, f, n, s. Here, pp is the cost per new napkin; mm is the number of days the fast laundry takes per napkin; ff is the cost per napkin at the fast laundry; nn is the number of days the slow laundry takes per napkin; ss is the cost per napkin at the slow laundry.

Output Format

Output the minimum total cost of napkin usage over the NN consecutive days.

3
1 7 5 
11 2 2 3 1

134

Hint

Constraints: For 100%100\% of the testdata, 1N2×1031 \le N \le 2 \times 10^3, 1ri1071 \le r_i \le 10^7, 1p,f,s1041 \le p, f, s \le 10^4.

Translated by ChatGPT 5