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.

Example

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.

题目大意是,给你一个字符串,再给你一个可添加的字符数,然后给你一个公式,要使某个值最大化.

根据公式的特点,我们把ai最大的字符放在越后面输出越好,所以,会出现这种形式:

原串+n个ai最大的字符

那么就解决了.

 #include<cstdio>
 #include<cstring>
 #include<algorithm>
 using namespace std;
 ],n,ans,x;
 int main(){
     ];
     scanf("%s",s);
     scanf("%d",&n);
     ; i<; i++) scanf("%d",&a[i]),x=max(x,a[i]);
     int len=strlen(s);
     ; i<len; i++) ans+=(i+)*a[s[i]-'a'];
     ; i++) ans+=(i+)*x;
     printf("%d",ans);
     ;
 }

[CodeForces - 447B] B - DZY Loves Strings的更多相关文章

  1. Codeforces Round #254 (Div. 1) D - DZY Loves Strings

    D - DZY Loves Strings 思路:感觉这种把询问按大小分成两类解决的问题都很不好想.. https://codeforces.com/blog/entry/12959 题解说得很清楚啦 ...

  2. Codeforces Round #254 (Div. 1) D. DZY Loves Strings hash 暴力

    D. DZY Loves Strings 题目连接: http://codeforces.com/contest/444/problem/D Description DZY loves strings ...

  3. 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 ...

  4. CF447B DZY Loves Strings 贪心

    DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter ...

  5. Codeforces 444 C - DZY Loves Colors

    C - DZY Loves Colors 思路: 分块,复杂度有点玄学,和普通分块不同的是在这个块被一次染色的时候暴力染整个块. 代码: #pragma GCC optimize(2) #pragma ...

  6. [CodeForces - 447E] E - DZY Loves Fibonacci Numbers

    E  DZY Loves Fibonacci Numbers In mathematical terms, the sequence Fn of Fibonacci numbers is define ...

  7. [CodeForces - 447D] D - DZY Loves Modification

    D - DZY Loves Modification As we know, DZY loves playing games. One day DZY decided to play with a n ...

  8. [CodeForces - 447C] C - DZY Loves Sequences

    C - DZY Loves Sequences DZY has a sequence a, consisting of n integers. We'll call a sequence ai, ai ...

  9. [CodeForces - 447A] A - DZY Loves Hash

    A - DZY Loves Hash DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert ...

随机推荐

  1. HDU 1298 T9(字典树+dfs)

    http://acm.hdu.edu.cn/showproblem.php?pid=1298 题意:模拟手机9键,给出每个单词的使用频率.现在给出按键的顺序,问每次按键后首字是什么(也就是要概率最大的 ...

  2. 百度地图自定义icon,定位偏移问题

    最近使用百度地图做一个调度系统,使用定义icon的marker,结果地图显示marker和实际位置偏移,最终参考文章: http://www.cnblogs.com/jz1108/archive/20 ...

  3. JVM——Java虚拟机架构

    0. 前言 Java虚拟机(Java virtualmachine)实现了Java语言最重要的特征:即平台无关性. 平台无关性原理:编译后的 Java程序(.class文件)由 JVM执行.JVM屏蔽 ...

  4. Android 虹软免费人脸识别 SDK开发

    目前我们的应用内使用了 ArcFace 的人脸检测功能,其他的我们并不了解,所以这里就和大家分享一下我们的集成过程和一些使用心得集成ArcFace FD 的集成过程非常简单在 ArcFace FD 的 ...

  5. 【转】 g++编译时对'xxxx'未定义的引用问题(undefined reference to)

    转自:https://blog.csdn.net/killwho/article/details/53785910 引用:http://www.linuxdiyf.com/linux/16754.ht ...

  6. C# ftp 上传、下载、删除

    public class FtpHelper { public static readonly FtpHelper Instance = new FtpHelper(); /// <summar ...

  7. 20180518VSTO多簿单表汇总

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsof ...

  8. catalan 递推

    http://www.cnblogs.com/zyt1253679098/p/9190217.html

  9. js新打开页面

    var a = document.createElement("a"); a.setAttribute("href", href); a.setAttribut ...

  10. Confluence 6 修改导航显示选项

    选择 子页面(Child pages)来在边栏中查看当前页面的子页面. 选择 页面树(Page tree)来查看整个空间的页面树,扩展当前的页面. 你也可以选择是否完全隐藏导航显示选项或者添加你希望可 ...