Codeforces Round #255(Div. 2)

来源:互联网 发布:mongodb与mysql区别 编辑:程序博客网 时间:2024/05/22 12:56
B. DZY Loves Strings

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

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?

Input

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 exceed 1000.

Output

Print a single integer — the largest possible value of the resulting string DZY could get.

Sample test(s)
input
abc31 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
output
41
题意:插入给定数量的字符,求出目标字符串的最大权值
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int main(){    char str[1005];    int k,i,sum,len;    int a[27];    scanf("%s",str);    len=strlen(str);    scanf("%d",&k);    for(i=0;i<26;i++)        scanf("%d",&a[i]);    sum=0;    for(i=0;i<len;i++)        sum+=a[str[i]-'a']*(i+1);    sort(a,a+26);    for(i=len+1;i<len+k+1;i++)        sum+=i*a[25];    printf("%d\n",sum);    return  0;}
0 0