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. SAP应用创新-维护控制表、视图统一路径

    SAP应用创新-维护控制表.视图统一路径 背景: Sap 里面通过技术支持人员维护表的值控制业务操作的表不少,一般通过事物代码或记录在系统外的文档或在某个程序上放置一个按钮.缺点:分散,不易记,不好找 ...

  2. HTTP Status 404 - No result defined for action com.ouyang.action.GreetingAction and result success 错误解决办法

    1.原来设置的包声明: <package name="myPackage" extends="struts-default"> <!-- 定义 ...

  3. sprinf sprintf_s 的用法

    函数功能: 将数据格式化输出到字符串 函数原型: int sprintf( char *buffer, const char *format [,argument] ... ) 注意这里的buffer ...

  4. MongoDB数据库的基本操作

    非关系型数据库(json数据库) npm install mongoose --save 启动数据酷: mongod --config /usr/local/etc/mongod.conf 这里可以将 ...

  5. CentOS 7 安装pip2

    使用yum安装python-pip,但是报错,说没有可用的包 安装epel源 [root@sishen yum.repos.d]# yum install -y epel-release 然后再安装 ...

  6. hibernate框架模板(可复制修改)

    简易搭建jar包 User类 package com.littlepage.test; public class User { private int uid; private String unam ...

  7. 力扣(LeetCode)832. 翻转图像

    给定一个二进制矩阵 A,我们想先水平翻转图像,然后反转图像并返回结果. 水平翻转图片就是将图片的每一行都进行翻转,即逆序.例如,水平翻转 [1, 1, 0] 的结果是 [0, 1, 1]. 反转图片的 ...

  8. TCP与UDP各自优缺点与区别

    TCP的优点: 可靠,稳定 TCP的可靠体现在TCP在传递数据之前,会有三次握手来建立连接,而且在数据传递时,有确认.窗口.重传.拥塞控制机制,在数据传完后,还会断开连接用来节约系统资源. TCP的缺 ...

  9. js常见知识点1.ajax相关

    一. javascript中的typeof返回哪些数据类型? 建议回复: typeof 运算符把类型信息当作字符串返回.typeof 返回值有六种可能: number, string, boolean ...

  10. Golang socket

    1.本例子实现了一个简单的TCP echo.客户端发送Hello,服务端回应World. 参考:<Socket编程> 2.服务端代码 package main import ( " ...