Tinkoff Internship Warmup Round 2018 and Codeforces Round #475 (Div. 2) B. Messages 题意+解析+ 答案

B. Messages
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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
Copy
4 5 5 3 5
1 5 5 4
Output
Copy
20
Input
Copy
5 3 1 1 3
2 2 2 1 1
Output
Copy
15
Input
Copy
5 5 3 4 5
1 2 3 4 5
Output
Copy
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.

题意:给你一系列消息,这些消息在第ti分钟收到,如果立即读这条消息可以获得a的金钱,不然没过一分钟获得金钱减少b,每一分钟可以获得c* k的金钱,k为没有读的消息的个数,求最后获得最大值的金钱

分析:假设每到一条消息我们都把他读了,我们将直接获得基本ans=n*a;通过题意我们发现如果对于每一道题每过一分钟收入为c-b,若c-b>0,消息读的越晚收入越多;c-b<0,消息读的越晚收入越少;c-b=0,消息什么时间读不影响收入。因此可分为三种情况,一,消息来了就读收益ans=n*a;二,拖到最后ans=n*a+sum*(c-b);/*sum为总共托的分数,*/ 三,可以归到前两种任意一种中

代码如下 
#include<bits/stdc++.h>

using namespace std;
int arr[1100];
int main()
{
    int n,a,b,c,t,ans=0,sum=0;
    cin >> n >> a>> b >> c >> t;
    for(int i=0;i<n;i++)
    {
        cin >> arr[i];
        sum+=t-arr[i];
    }
    ans=n*a;
    if(b>=c)
    {
        cout << ans << endl;
    }
    else
    {
        cout << ans+sum*(c-b) << endl;
    }
    return 0;
}

阅读更多
个人分类: cf 数学
上一篇Tinkoff Internship Warmup Round 2018 and Codeforces Round #475 (Div. 2) A. Splits 水题 题意+解析+ 答案
下一篇Tinkoff Internship Warmup Round 2018 and Codeforces Round #475 (Div. 2) C.Alternating Sum 题意+解析+ 答案
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭