964B.md (1987B)
1 Source: https://codeforces.com/problemset/problem/964/B 2 3 B. Messages 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 There are *n* incoming messages for Vasya. The *i*-th message is going to be received after *t**i* 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. 22 23 Also, each minute Vasya's bank account receives *C*·*k*, where *k* is the amount of received but unread messages. 24 25 Vasya's messages are very important to him, and because of that he wants to have all messages read after *T* minutes. 26 27 Determine the maximum amount of money Vasya's bank account can hold after *T* minutes. 28 29 Input 30 31 The first line contains five integers *n*, *A*, *B*, *C* and *T* (1 ≤ *n*, *A*, *B*, *C*, *T* ≤ 1000). 32 33 The second string contains *n* integers *t**i* (1 ≤ *t**i* ≤ *T*). 34 35 Output 36 37 Output one integer — the answer to the problem. 38 39 Examples 40 41 Input 42 43 ``` 44 4 5 5 3 5 45 1 5 5 4 46 ``` 47 48 Output 49 50 ``` 51 20 52 ``` 53 54 Input 55 56 ``` 57 5 3 1 1 3 58 2 2 2 1 1 59 ``` 60 61 Output 62 63 ``` 64 15 65 ``` 66 67 Input 68 69 ``` 70 5 5 3 4 5 71 1 2 3 4 5 72 ``` 73 74 Output 75 76 ``` 77 35 78 ``` 79 80 Note 81 82 In the first sample the messages must be read immediately after receiving, Vasya receives *A* points for each message, *n*·*A* = 20 in total. 83 84 In the second sample the messages can be read at any integer moment. 85 86 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.