[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 ...
随机推荐
- 2、Python程序控制结构(0530)
条件测试: 1.if 条件测试表达式 python的比较操作 1.所有的python对象都支持比较操作 可用于测试相等性.相对大小等: 如果是符合对象,python会检查其所有部分,包括自动遍历各级嵌 ...
- Linux 命令之split(将一个大文件根据行数平均分成若干个小文件)
把一个 txt 文件导入到 excel 中,但是 excel 单列支持的行数为 1048576,而我需要导入的 txt 文件总共有 7945674 ,我们无法一次性将整个 txt 文件里面的内容导入到 ...
- App.Config自定义配置节点
配置文件: <?xml version="1.0" encoding="utf-8"?> <configuration> <con ...
- 学习笔记57—归一化 (Normalization)、标准化 (Standardization)和中心化/零均值化 (Zero-centered)
1 概念 归一化:1)把数据变成(0,1)或者(1,1)之间的小数.主要是为了数据处理方便提出来的,把数据映射到0-1范围之内处理,更加便捷快速.2)把有量纲表达式变成无量纲表达式,便于不同单位或 ...
- feed
a1=tf.placeholder(tf.float32) # 占位符 a2=tf.placeholder(tf.float32)r=tf.multiply(a1,a2) with tf.Ses ...
- 使用http://start.spring.io/ 生成工程
今天学习spring-cloud,无意中发现一个spring提供的构建工程的页面,想记录下,发现有个博客写的很好就直接抄过来了. 原文链接: https://blog.csdn.net/u01050 ...
- linux修改网卡名为eth0
方法1: 1.编辑网卡的配置文件 vi /etc/sysconfig/network-scripts/ifcfg-ens33 将里面的NAME和DEVICE项修改为eth0,ONBOOT修改为yes. ...
- Linux下的常用指令汇总
内容提纲: 1.ubuntu安装 2.linux目录结构 3.apt.dpkg 4.date.cal.tzselect 5.修改密码.忘记密码 6.注销/重启/关机 7.cd pwd 8.-h --h ...
- jenkins之从0到1利用Git和Ant插件打war包并自动部署到tomcat(第三话):创建一个自由风格的项目(非maven),实现自动打war包
上一节把git和ant安装在虚拟机,并在jenkins上做了相关配置,接下来就可以真正开始构建一个项目了 1.新建一个自由风格的项目,因为是用ant打包,所以不要选择构建maven项目 2.配置源码管 ...
- 利用Anaconda完美解决Python 2与python 3的共存问题
前言 现在Python3 被越来越多的开发者所接受,同时让人尴尬的是很多遗留的老系统依旧运行在 Python2 的环境中,因此有时你不得不同时在两个版本中进行开发,调试. 如何在系统中同时共存 Pyt ...