Codeforces 964-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 nABC 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 1234 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 的时候,我们收到邮件就直接打开,并且直接按照此规则计费。

当c < b 时,我们在t时刻一起打开,并按照此规则计费。

别问我为什么这么搞,看样例蒙的。

#include<bits/stdc++.h>
#define LL long long
using namespace std;


const int MAX = 1e3+10;
const int INF = 0x3fffffff;

struct node {
    int value;
    int time;
}p[MAX];

int main(){
    int n,a,b,c,t;
    while(scanf("%d%d%d%d%d",&n,&a,&b,&c,&t)!=EOF){
        memset(p,0,sizeof(p));
        for(int i=0;i<n;i++){
            p[i].value = a;
            scanf("%d",&p[i].time);
            p[i].value -= (t-p[i].time)*b;
        }

        if(b>=c){
            cout<<n*a<<endl;
        }
        else{
            int te = 0;
            for(int i=0;i<n;i++){
                te += p[i].value;
            }
            int sum = 0;
            for(int i=0;i<n;i++){
                sum += (t - p[i].time) * c;
            }
            cout<<sum + te<<endl;
        }
    }
    return 0;
}
    原文作者:B树
    原文地址: https://blog.csdn.net/l18339702017/article/details/79983381
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞