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
  1. 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
  1. 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最大的字符

那么就解决了.

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. using namespace std;
  5. ],n,ans,x;
  6. int main(){
  7. ];
  8. scanf("%s",s);
  9. scanf("%d",&n);
  10. ; i<; i++) scanf("%d",&a[i]),x=max(x,a[i]);
  11. int len=strlen(s);
  12. ; i<len; i++) ans+=(i+)*a[s[i]-'a'];
  13. ; i++) ans+=(i+)*x;
  14. printf("%d",ans);
  15. ;
  16. }

[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. POJ 2718 Smallest Difference(最小差)

     Smallest Difference(最小差) Time Limit: 1000MS    Memory Limit: 65536K Description - 题目描述 Given a numb ...

  2. VHDL 类型转换

    STD_LOGIC_1164包集合 函 数 名 功 能 TO_STDLOGICVECTOR(A) 由BIT_VECTOR转换为STD_LOGIC_VECTOR TO_BITVECTOR(A) 由STD ...

  3. Linux命令之rz命令与sz命令

    1.rz命令 rz命令(Receive ZMODEM),使用ZMODEM协议,将本地文件批量上传到远程Linux/Unix服务器,注意不能上传文件夹. 当我们使用虚拟终端软件,如Xshell.Secu ...

  4. centos7 安装nexus3

    一.安装前先安装好java JDK 和maven nexus 下载 链接:https://pan.baidu.com/s/1qQBNj2soc8Un4AoRejvEyw 密码: sb12 1.下载好后 ...

  5. Python 模块(module)

    模块(module)也是为了同样的目的.在Python中,一个.py文件就构成一个模块.通过模块,你可以调用其它文件中的程序. first.py def laugh(): print "Ha ...

  6. python中shutil模块

    shutil是对OS中文件操作的补充:移动.复制.打包.压缩.解压. 1.copy文件内容到另一个文件,可以copy指定大小的内容. shutil.copyfileobj(fsrc, fdst[, l ...

  7. Token和SessionStorage(会话存储对象)

    sessionStorage数据只在当前标签页共享 存在本地   关闭浏览器后会清除数据(关闭标签页不会清楚) localStorage数据会存在浏览器中  浏览器关了数据也还在 只有清除缓存才会消失 ...

  8. 牛客OI周赛6-提高组 A 大法师与魔法石

    大法师与魔法石 思路: 对于一个ai, 它可以构成区间[ai/v, ai] 假设和它相邻的为aj, 那么ai 和 aj 构成的区间为[(ai+aj) / v, ai+aj] 那么这两个区间能合并的条件 ...

  9. eclipse中怎么调出左边项目列表,解决方法:主界面的最上面一栏的Window--ShowView--Project Explorer

    主界面的最上面一栏的Window--ShowView--Project Explorer

  10. 第 4 章 容器 - 029 - 限制容器的 Block IO

    限制容器的 Block IO Block IO 是另一种可以限制容器使用的资源. Block IO 指的是磁盘的读写,docker 可通过设置权重.限制 bps 和 iops 的方式控制容器读写磁盘的 ...