Messages (贪心)

There are n incoming messages for Vasya. The i-th message is going to be received after ti minutes. Each message has a cost, which equals to A initially. After being received, the cost of a message decreases by B each minute (it can become negative). Vasya can read any message after receiving it at any moment of time. After reading the message, Vasya's bank account receives the current cost of this message. Initially, Vasya's bank account is at 0.

Also, each minute Vasya's bank account receives C·k, where k is the amount of received but unread messages.

Vasya's messages are very important to him, and because of that he wants to have all messages read after T minutes.

Determine the maximum amount of money Vasya's bank account can hold after T minutes.


Input

The first line contains five integers n, A, B, C and T (1 ≤ n, A, B, C, T ≤ 1000).

The second string contains n integers ti (1 ≤ ti ≤ T).

Output

Output one integer  — the answer to the problem.

Examples
Input
4 5 5 3 5
1 5 5 4
Output
20
Input
5 3 1 1 3
2 2 2 1 1
Output
15
Input
5 5 3 4 5
1 2 3 4 5
Output
35
Note

In the first sample the messages must be read immediately after receiving, Vasya receives A points for each message, n·A = 20 in total.

In the second sample the messages can be read at any integer moment.

In the third sample messages must be read at the moment T. This way Vasya has 1, 2, 3, 4 and 0 unread messages at the corresponding minutes, he gets 40 points for them. When reading messages, he receives (5 - 4·3) + (5 - 3·3) + (5 - 2·3) + (5 - 1·3) + 5 =  - 5 points. This is 35 in total.

题意:一共有n封信件分别将在ti时刻发到邮箱,可以在收到后的任意时刻阅读,但是必须在T分钟内读完所有信件,任意时刻可以读任意封信件,每个信件有初始价值A,收到后如果不读,每分钟价值将减少B,并且每分钟账户将会增加C*k数量的价值(k为邮箱内未读信件的数量),求账户的最大价值。思路:任意一封信件可以在收到后的任意时刻读,设账户的总价值为ans,

1.如果所有信件在收到的时候读,账户的总价值ans= n*A;

2.若C>B,则对于一封信件,每分钟的收入为C-B>0,我们选择在最后时刻阅读,收入为ans+=(B-C)*(T-ti)

代码:

#include<cstdio>
#include<cstring>
using namespace std;
const int N = 1005;
int main(){
	int n,A,B,C,T;
	scanf("%d%d%d%d%d",&n,&A,&B,&C,&T);
	int ans=n*A;
	for(int i=0;i<n;i++){
		int x;
		scanf("%d",&x);
		if(B<C) ans+=(C-B)*(T-x);
	}
	printf("%d\n",ans);
	return 0;
}
/*
n A B C T
5 5 3 4 5
1 2 3 4 5*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值