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. 复习ing

    记不住啊,我能有什么办法,只好一遍又一遍看

  2. 文档对象模型DOM

    文档对象模型 DOM 1 DOM概述 1.1 什么是DOM 文档对象模型 Document Object Model 提供给用户操作document obj 的标准接口 文档对象模型 是表示和操作 H ...

  3. Python Scrapy安装

    直接安装scrapy 各种报错,后来各种百度终于解决了,如下是亲身的经历. pip install scrapy 这样直接会报错. 第一步: 先安装wheel pip install wheel 第二 ...

  4. 有了art-template,如有神助

    <div class="form-group col-lg-12"> <label class="control-label col-lg-3 text ...

  5. (转)Windows上搭建Kafka运行环境

    转自:<Windows上搭建Kafka运行环境> 完整解决方案请参考: Setting Up and Running Apache Kafka on Windows OS   在环境搭建过 ...

  6. ionic toggle点击返回true/false支持自定义

    <ul class="list"> <li class="item item-toggle"> 手机提醒 <label class ...

  7. python requests库与json数据处理详解

    1. http://docs.python-requests.org/zh_CN/latest/user/quickstart.html get方法将参数放在url里面,安全性不高,但是效率高:pos ...

  8. 如何通过 Terminal 设置截图存储的位置

    由于截图的默认位置是存储在 desktop 上的,而 desktop 又是我们经常见的地方,有一个干净的界面对良好的电脑的体验非常重要,那么可以通过改变截图的默认的存储位置来改变.而改变这一路径需要用 ...

  9. 4步win7下简单FTP服务器搭建(试验成功)

    本文介绍通过win7自带的IIS来搭建一个只能实现基本功能的FTP服务器,第一次装好WIN7后我愣是没整出来,后来查了一下网上资料经过试验后搭建成功,其实原理和步骤与windows前期的版本差不多,主 ...

  10. android -------- Lint优化工具

    什么是 Lint Lint 是Android Studio 提供的 代码扫描分析工具,它可以帮助我们发现代码结构/质量问题,同时提供一些解决方案,而且这个过程不需要我们手写测试用例. Lint 发现的 ...