GYM

来源:互联网 发布:淘宝网成功的原因 编辑:程序博客网 时间:2024/05/17 23:48

Dragon Delivers
time limit per test
2.0 s
memory limit per test
256 MB
input
standard input
output
standard output

I stood just in front of an enormous castle of black stone, and rain water flowed down its walls. From afar I could see a tall tower with a light in the top room of it. I felt Dragon was there. He always liked to be higher than others. Somewhere inside there was also an alchemical laboratory which produced Blue Tea. There it was packed and then delivered to customers all over the city, just like pizza or hamburgers.

Orders came via pigeon post at the moments of time ti. One instant delivery of Tea cost Dragon d pieces of gold, but it could unite any number of previously received orders. Delay of every order cost c pieces of gold per unit of time. The system was adjusted and worked like a clockwork in order to minimize the total expenses for deliveries, and knights were submissively closing their eyes to it. Gold always was harmful to people's eyesight.

Input

The first line contains three integers separated by spaces: nd and c (1 ≤ n ≤ 1031 ≤ d ≤ 1091 ≤ c ≤ 106) — the number of orders, the cost of one delivery and the cost of delay for one unit of time, correspondingly.

The second line contains n integers separated by spaces: ti (0 ≤ ti ≤ 109) — the moments of time when the orders are received. It is guaranteed that the sequence of these moments is strictly increasing, that is, ti < ti + 1.

Output

Output one integer — the minimal total cost of all deliveries.

Examples
input
3 3 22 5 7
output
9
input
3 3 12 5 6
output
7
Note

In the first sample it's more profitable to deliver each of three orders at the moments when they are received, and in the second sample it's better to deliver the second order together with the third one.




题意:你可以一次发很多个包裹,花费为D,一个包裹延迟1s,收费D元,求最小花费。


解题思路:DP即可,详见代码,很好懂,区间DP的思想。对于每一个DP[i],枚举分割点j,即在j之后的都延迟发送包裹。



#include <iostream>#include <algorithm>#include <string>#include <vector>#include <memory.h>using namespace std;typedef long long int ll;int N,D,C;ll a[1005];ll sum[1005];//记录前缀和,用于优化计算速度ll dp[1005];//记录只考虑前i个的时候的最优值int main(){    scanf("%d%d%d",&N,&D,&C);    for(int i=1;i<=N;i++){        scanf("%lld",&a[i]);        sum[i]=sum[i-1]+a[i];    }    memset(dp,0x3f,sizeof(dp));    dp[0]=0;    for(int i=1;i<=N;i++)        for(int j=0;j<i;j++)            dp[i]=min(dp[i],dp[j]+((i-j)*a[i]-(sum[i]-sum[j]))*C+D);    //原本是要把a[j]-a[i]的和计算一遍,这里直接用一个公式算出来即可。不用循环。        printf("%lld\n",dp[N]);    return 0;}