Codeforces Round #FF (Div. 2) B. DZY Loves Strings

B. DZY Loves Strings
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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
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
output
41
Note

In the test sample DZY can obtain "abcbbc", value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.

题目大意:给出一个字符串(小写字母)和26个小写字母的权值 在给出一个数字表示要添加的字母的数量 问添加后字符串的值最大为多少

#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int n,i,t,sum,maxn,l;
    char a[1005];
    int b[30];
    while(cin>>a)
    {
        sum=0;

        cin>>t;
        for(i=0;i<26;i++)
            cin>>b[i];
        for(i=0;i<strlen(a);i++)
            {
                l=a[i]-'a';
                sum+=b[l]*(i+1);

            }
       maxn=b[0];
        for(i=0;i<26;i++)
            if(maxn<b[i])
            maxn=b[i];
        for(i=strlen(a);i<strlen(a)+t;i++)
        sum+=maxn*(i+1);
        cout<<sum<<endl;

    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值