DZY loves collecting special strings which only contain lowercase letters. For each lowercase letterc DZY knows its valuewc. For each special strings = s1s2...s|s| (|s| is the length of the string) he represents its value with a functionf(s), where

Now DZY has a string s. He wants to insertk 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 towz. 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 <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
const int maxn=1000+10;
char s[maxn];
int aa[26];
int b[maxn];
map<char,int>mm;
vector<int>q;
int main()
{
int k;
while(cin>>s)
{
int maxa=-1;
int len=strlen(s);
scanf("%d",&k);
for(int i=0;i<26;i++)
{
cin>>aa[i];
maxa=max(maxa,aa[i]);
mm['a'+i]=aa[i];
}
for(int i=0;i<len;i++)
{
b[i]=mm[s[i]];
q.push_back(b[i]);
}
int ans=0;
int c=lower_bound(b,b+len,maxa)-b;
for(int i=0;i<len;i++)
{
ans+=mm[s[i]]*(i+1);
}
for(int i=len;i<len+k;i++)
{
ans+=maxa*(i+1);
}
cout<<ans<<endl;
}
return 0;
}