CodeForces 964B Messages

Description:

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.

題目大意:
已知你會收到n封信。在某時刻t時會來一封或多封,每封信初始價值爲a,從第t+1開始每時刻的價值減少b(最終價值可以爲負數)。 同時銀行有一種收益爲c * 收到但是沒有讀過的信的數目。我們可以選擇每封信何時讀只要保證收益最大即可。

解題思路:
一開始思路想的是比較c和b的大小, c大的話就全部放在最後讀,否則就立即讀。 但是這樣寫全部最後讀就很麻煩。 我們可以換一種思路, 反正要麼是立即讀要麼是最後讀要麼立即讀, 我們可以計算出這兩種決策最後的收益選擇大的即可。

代碼:
#include <iostream>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <utility>
#include <string>
#include <cmath>
#include <vector>
#include <bitset>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
using namespace std;
/*tools:
*ios::sync_with_stdio(false);
*freopen("input.txt", "r", stdin);
*/

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int dir[9][2] = { 0, 1, 0, -1, 1, 0, -1, 0, 1, 1, 1, -1, -1, 1, -1, -1, 0, 0 };
const int inf = 0x3f3f3f;
const double pi = acos(-1.0);
const int mod = (ll) 1e9 + 7;
const int Max = (int) 1e3 + 51;
const ld eps = 1e-10;
int arr[Max];
int acc[Max];
int main() {
    // definition
    int n, a, b, c, t, sum = 0;
    cin >> n >> a >> b >> c >> t;
    // initialization
    int x;
    for (int i = 0; i < n; ++i) {
        cin >> x;
        sum += t - x;
    }
    // perform
    int sum1 = a * n;
    int sum2 = (n * a) + (c - b) * sum;
    int ans = max(sum1, sum2);
    printf("%d\n", ans);
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章