447B.md (1394B)
1 Source: https://codeforces.com/problemset/problem/447/B 2 3 B. DZY Loves Strings 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 stdin 16 17 output 18 19 stdout 20 21 DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s* = *s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where 22 23  24 25 Now DZY has a string *s*. He wants to insert *k* lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get? 26 27 Input 28 29 The first line contains a single string *s* (1 ≤ |*s*| ≤ 103). 30 31 The second line contains a single integer *k* (0 ≤ *k* ≤ 103). 32 33 The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000. 34 35 Output 36 37 Print a single integer — the largest possible value of the resulting string DZY could get. 38 39 Examples 40 41 Input 42 43 ``` 44 abc 45 3 46 1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 47 ``` 48 49 Output 50 51 ``` 52 41 53 ``` 54 55 Note 56 57 In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.