[CodeForces - 447B] B - DZY Loves Strings
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
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
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的更多相关文章
- Codeforces Round #254 (Div. 1) D - DZY Loves Strings
D - DZY Loves Strings 思路:感觉这种把询问按大小分成两类解决的问题都很不好想.. https://codeforces.com/blog/entry/12959 题解说得很清楚啦 ...
- 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 ...
- 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 ...
- CF447B DZY Loves Strings 贪心
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter ...
- Codeforces 444 C - DZY Loves Colors
C - DZY Loves Colors 思路: 分块,复杂度有点玄学,和普通分块不同的是在这个块被一次染色的时候暴力染整个块. 代码: #pragma GCC optimize(2) #pragma ...
- [CodeForces - 447E] E - DZY Loves Fibonacci Numbers
E DZY Loves Fibonacci Numbers In mathematical terms, the sequence Fn of Fibonacci numbers is define ...
- [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 ...
- [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 ...
- [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 ...
随机推荐
- Go 灵活多变的切片Slice
我们知道数组定义好之后其长度就无法再修改,但是,在实际开发过程中,有时候我们并不知道需要多大的数组,我们期望数组的长度是可变的, 在 Go 中有一种数据结构切片(Slice) 解决了这个问题,它是可变 ...
- struct和typedef struct用法和区别
1 首先://注意在C和C++里不同 1.1 在C中定义一个结构体类型要用typedef: typedef struct Student { int a; }Stu; 于是在声明变量的时候就可:Stu ...
- @Autowired 警告 Field injection is not recommended Spring @Autowired注入
问题: 一. 在IDEA升级2017版后,发现以前使用的 @Autowired 出现了个警告 Field injection is not recommended. @Autowired的三种使用方式 ...
- 遍历一个可迭代对象中的所有元素,但是却不想使用for循环
def manual_iter(): with open('/etc/passwd') as f: try: while True: line = next(f) print(line, end='' ...
- pandas计数 value_counts()
来自:曹骥 在pandas里面常用value_counts确认数据出现的频率. 1. Series 情况下: pandas 的 value_counts() 函数可以对Series里面的每个值进行计数 ...
- MySQL基本使用
来自李兴华视频. 1. 启动命令行方式 2. 连接mysql数据库,其中“-u”标记的是输入用户名,“-p”标记的是输入密码. 3. 建立一个新数据库——mldn,使用UTF-8编码: create ...
- 力扣 报错 runtime error: load of null pointer of type 'const int'
runtime error: load of null pointer of type 'const int' 要求返回的是int* 解决方案 1.指针使用malloc分配空间 用 int * p = ...
- input 输入值的监听 禁止输入特殊字符
1.input 输入值的监听 //用于监听input的值变化(input的值产生变化才会触发事件) (function ($) { $.fn.watch = function (callback) ...
- 学习笔记29—Linux基础
一.简单命令: 1.进入文件夹heyi目录:cd ./heyi 2.查看该目录下内容:ls 二.linux压缩和解压缩命令大全 tar命令 解包:tar zxvf FileName.tar 打包:ta ...
- 学习笔记14—Python error集
1.Can't broadcast input array from shape (3,1) into shape (3,) resolution: V[k:m,k] = v; v has sh ...