您的位置:首页 > 其它

CodeForces 447B---DZY Loves Strings

2016-04-20 21:43 337 查看
C - DZY Loves Strings

Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u

Submit

Status

Practice

CodeForces 447B

Description

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 Input

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

Hint

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>
using namespace std;
int v[30];
int main()
{
string a;
cin>>a;
int k;
int sum=0;
scanf("%d",&k);
int maxn;
for(int i=1;i<=26;i++)
{
cin>>v[i];
}
maxn=*max_element(v,v+26);
int l=a.length();
for(int i=1;i<=l;i++)
{
for(int j=1;j<=26;j++)
{
if((j-1)==a[i-1]-'a')
{
sum+=v[j]*i;
break;
}
}
}
for(int i=l+1;i<=l+k;i++)
{
sum+=maxn*i;
}
cout<<sum<<endl;
return 0;
}


仅代表个人观点,欢迎交流探讨,勿喷~~~



PhotoBy:WLOP

http://weibo.com/wlop
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: