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.
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 one integer — the answer to the problem.
4 5 5 3 5 1 5 5 4
20
5 3 1 1 3 2 2 2 1 1
15
5 5 3 4 5 1 2 3 4 5
35
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.
思路:收到一条信息后,这一条信息每过一分钟钱会少B,但是同时会加C。所以对比B和C的大小就行了,当B小于等于C的时候,过得越久损失越大,收到信息的时候就立马阅读。当B大于C时,在最后限制时间再阅读,收益最大化。
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int a[1005];
int main()
{
int n,m,t,A,B,C,T;
scanf("%d%d%d%d%d",&n,&A,&B,&C,&T);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
int sum=0;
if(B>=C)
sum=A*n;
else
{
for(int i=1;i<=n;i++)
sum=sum+A+(T-a[i])*(C-B);
}
printf("%d\n",sum);
}