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

来源:互联网 发布:centos 不显示中文 编辑:程序博客网 时间:2024/05/22 01:51
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
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
Note

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


题意:有一个字符串s,由小写字母组成,它的价值为,w(s)是一个函数,输入给的,每个字母对应一个值。然后可以插入k个字符,求插入后的最大价值。

思路:贪心。先算出原字符串的价值,k个字符全插入在后面,就插函数值最大的那个字符。

#include <iostream>#include <stdio.h>#include <cmath>#include <algorithm>#include <iomanip>#include <cstdlib>#include <string>#include <memory.h>#include <vector>#include <queue>#include <stack>#include <ctype.h>#define INF 1000000000using namespace std;char str[1010];int k;//int tab[30];int main(){while(cin>>str){cin>>k;int maxf=0;for(int i=1;i<=26;i++){cin>>tab[i];if(tab[i]>maxf)maxf=tab[i];}int ans=0;for(int i=0;i<strlen(str);i++){ans+=(i+1)*tab[str[i]-96];}for(int i=strlen(str)+1;i<strlen(str)+1+k;i++){ans+=maxf*i;}cout<<ans<<endl;}return 0;} 


0 0
原创粉丝点击