*思路为对26个字母的价值进行排序,找到最大的价值,加最大的价值的字母往后放,价值最大。
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where
![](https://i-blog.csdnimg.cn/blog_migrate/c5df6a3067a273101e5af02392de4243.png)
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?
The first line contains a single string s (1 ≤ |s| ≤ 103).
The second line contains a single integer k (0 ≤ k ≤ 103).
The third line contains twenty-six integers from wa to wz. Each such number is non-negative and doesn't exceed1000.
Print a single integer — the largest possible value of the resulting string DZY could get.
abc 3 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
41
In the test sample DZY can obtain "abcbbc", value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
char s[1005];
int k;
int x[26];
int i;
int j;
int sum=0;
int n;
scanf("%s",s);
scanf("%d",&k);
for(i=0;i<26;i++)
scanf("%d",&x[i]);
n=strlen(s);
for(i=1;i<=n;i++)
sum+=x[(s[i-1]-'a')]*i;
sort(x,x+26);
for(j=n+1;j<=n+k;j++)
sum+=x[25]*j;
printf("%d\n",sum);
return 0;
}