C. Brutality Educational Codeforces Round 59 (Rated for Div. 2) 贪心+思维
1 second
256 megabytes
standard input
standard output
You are playing a new famous fighting game: Kortal Mombat XII. You have to perform a brutality on your opponent's character.
You are playing the game on the new generation console so your gamepad have 2626 buttons. Each button has a single lowercase Latin letter from 'a' to 'z' written on it. All the letters on buttons are pairwise distinct.
You are given a sequence of hits, the ii-th hit deals aiai units of damage to the opponent's character. To perform the ii-th hit you have to press the button sisi on your gamepad. Hits are numbered from 11 to nn.
You know that if you press some button more than kk times in a row then it'll break. You cherish your gamepad and don't want to break any of its buttons.
To perform a brutality you have to land some of the hits of the given sequence. You are allowed to skip any of them, however changing the initial order of the sequence is prohibited. The total damage dealt is the sum of aiai over all ii for the hits which weren't skipped.
Note that if you skip the hit then the counter of consecutive presses the button won't reset.
Your task is to skip some hits to deal the maximum possible total damage to the opponent's character and not break your gamepad buttons.
The first line of the input contains two integers nn and kk (1≤k≤n≤2⋅1051≤k≤n≤2⋅105) — the number of hits and the maximum number of times you can push the same button in a row.
The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109), where aiai is the damage of the ii-th hit.
The third line of the input contains the string ss consisting of exactly nn lowercase Latin letters — the sequence of hits (each character is the letter on the button you need to press to perform the corresponding hit).
Print one integer dmgdmg — the maximum possible damage to the opponent's character you can deal without breaking your gamepad buttons.
7 3
1 5 16 18 7 2 10
baaaaca
54
5 5
2 4 1 3 1000
aaaaa
1010
5 4
2 4 1 3 1000
aaaaa
1009
8 1
10 15 2 1 4 8 15 16
qqwweerr
41
6 3
14 18 9 19 2 15
cccccc
52
2 1
10 10
10
In the first example you can choose hits with numbers [1,3,4,5,6,7][1,3,4,5,6,7] with the total damage 1+16+18+7+2+10=541+16+18+7+2+10=54.
In the second example you can choose all hits so the total damage is 2+4+1+3+1000=10102+4+1+3+1000=1010.
In the third example you can choose all hits expect the third one so the total damage is 2+4+3+1000=10092+4+3+1000=1009.
In the fourth example you can choose hits with numbers [2,3,6,8][2,3,6,8]. Only this way you can reach the maximum total damage 15+2+8+16=4115+2+8+16=41.
In the fifth example you can choose only hits with numbers [2,4,6][2,4,6] with the total damage 18+19+15=5218+19+15=52.
In the sixth example you can change either first hit or the second hit (it does not matter) with the total damage 1010.
题目大意:
给你一个数字n和k,n代表有n次操作,k代表一个按钮最大连续按的次数。
接下来就是一行数字,代表这一次的伤害值,
接下来又是一串字母,这个代表第i次操作要按的按钮,这个与上面的相对应,让你求最大的伤害值。
这个就是一个贪心的题目,需要你仔细一点,这个题目读懂就好写了,这个就是如果要连续按下同一个按钮就超过k次这个按钮就错了,
但是呢,如果中途有别的按钮按了,这个按钮之前的次数就会消除。
C. Brutality Educational Codeforces Round 59 (Rated for Div. 2) 贪心+思维的更多相关文章
- Educational Codeforces Round 59 (Rated for Div. 2) DE题解
Educational Codeforces Round 59 (Rated for Div. 2) D. Compression 题目链接:https://codeforces.com/contes ...
- Educational Codeforces Round 59 (Rated for Div. 2) (前四题)
A. Digits Sequence Dividing(英文速读) 练习英语速读的题,我还上来昏迷一次....只要长度大于2那么一定可以等于2那么前面大于后面就行其他no 大于2的时候分成前面1个剩下 ...
- Educational Codeforces Round 59 (Rated for Div. 2) E 区间dp + 状态定义 + dp预处理(分步dp)
https://codeforces.com/contest/1107/problem/E 题意 给出01字符串s(n<=100),相邻且相同的字符可以同时消去,一次性消去i个字符的分数是\(a ...
- Educational Codeforces Round 59 (Rated for Div. 2)
熬夜爆肝,智商急剧下降 坐标UTC+8晚上23:35开始 晚上脑袋转的慢,非常慢 T1上来先做还花了好几分钟 T2本来是有式子的我TM写数位DP写炸了然后才发现是有公式 T3英语不好,一开始题意没读懂 ...
- 【考试记录】Educational Codeforces Round 59 (Rated for Div. 2)
本来准备划水,结果被垃圾题艹翻了…… T2题意: 定义一个数$x$的数字根$S(x)$为:将其各位数字相加得到一个新数,再将新数的数字和相加直到得到一个个位数,就是该数的数字根. 例如:$S(38)= ...
- C. Playlist Educational Codeforces Round 62 (Rated for Div. 2) 贪心+优先队列
C. Playlist time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
随机推荐
- C# 使用 PerformanceCounter 获取 CPU 和 硬盘的使用率
C# 使用 PerformanceCounter 获取 CPU 和 硬盘的使用率: 先看界面: 建一个 Windows Form 桌面程序,代码如下: using System; using Sys ...
- C#中设置窗口在最前显示而其他窗口不能使用
对程序中的一个Form1处理,让其在打开的情况下,其他窗体都无法使用,全部焦点都在他身上. 1.这种方法最简单,直接调用窗体的模态对话框函数显示窗体 Form1.ShowDialog(): 2.设置窗 ...
- codeM美团编程大赛初赛B轮D题(考验你的数学思维!)
[编程题] 模 时间限制:1秒空间限制:32768K 给定四个正整数a,b,c,k,回答是否存在一个正整数n,使得a*n在k进制表示下的各位的数值之和模b为c.输入描述:第一行一个整数T(T < ...
- 【Redis】2、CentOS 7 上安装 redis3.2.3安装与配置
一.redis源码安装 [更正]现在最新稳定的版本已经到了3.2.8 截至到2016.8.11,redis最新稳定版本为3.2.3.本篇文章我们就以此版本为基础,进行相关的讲解. 下载redis源码, ...
- 【Spring】31、Spring的EL表达式
一.简介 Spring3中引入了Spring表达式语言—SpringEL,SpEL是一种强大,简洁的装配Bean的方式,他可以通过运行期间执行的表达式将值装配到我们的属性或构造函数当中,更可以调用JD ...
- Java 控制类的引用类型,合理使用内存
Java提供了 java.lang.ref包,该包下的类均与垃圾回收机制相关 先介绍Java对象的集中引用类型 1.强引用 强引用是最常见的,创建对象就是强引用,如 String a = new St ...
- js 字符串转数组
var obj = "123456".replace(/(.)(?=[^$])/g, "$1,").split(","); conso ...
- Vue 组件之间传值
一.父组件向子组件传递数据 在 Vue 中,可以使用 props 向子组件传递数据. 子组件部分: 这是 header.vue 的 HTML 部分,logo 是在 data 中定义的变量. 如果需要从 ...
- Android getprop 读取的属性哪里来的?
Android getprop 和 setprop 可以对系统属性进行读取和设置. 通过串口执行以下 geyprop 打印出来的属性让你一目了然. 属性出来了,但是在哪里设置的呢,这里有两个 ...
- Html:html是什麽、html文件结构
相关内容: html是什麽 html文件结构 首发日期:2018-02-12 html是什么: hmtl超文本标记语言,标准通用标记语言下的一个应用. html专门用于网页,它的“标志符”告诉了浏览器 ...