A12278 | Brutality
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The first line of the input contains two integers $n$ and $k$ ( $1 \le k \le n \le 2 \cdot 10^5$ ) — 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 $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 10^9$ ), where $a_i$ is the damage of the $i$ -th hit.
The third line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters — the sequence of hits (each character is the letter on the button you need to press to perform the corresponding hit).
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 10^9$ ), where $a_i$ is the damage of the $i$ -th hit.
The third line of the input contains the string $s$ consisting of exactly $n$ 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 $dmg$ — the maximum possible damage to the opponent's character you can deal without breaking your gamepad buttons.
输出格式
In the first example you can choose hits with numbers $[1, 3, 4, 5, 6, 7]$ with the total damage $1 + 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 = 1010$ .
In the third example you can choose all hits expect the third one so the total damage is $2 + 4 + 3 + 1000 = 1009$ .
In the fourth example you can choose hits with numbers $[2, 3, 6, 8]$ . Only this way you can reach the maximum total damage $15 + 2 + 8 + 16 = 41$ .
In the fifth example you can choose only hits with numbers $[2, 4, 6]$ with the total damage $18 + 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 $10$ .
In the second example you can choose all hits so the total damage is $2 + 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 = 1009$ .
In the fourth example you can choose hits with numbers $[2, 3, 6, 8]$ . Only this way you can reach the maximum total damage $15 + 2 + 8 + 16 = 41$ .
In the fifth example you can choose only hits with numbers $[2, 4, 6]$ with the total damage $18 + 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 $10$ .
输入输出样例
输入 #1
7 3 1 5 16 18 7 2 10 baaaaca
输出 #1
54
输入 #2
5 5 2 4 1 3 1000 aaaaa
输出 #2
1010
输入 #3
5 4 2 4 1 3 1000 aaaaa
输出 #3
1009
输入 #4
8 1 10 15 2 1 4 8 15 16 qqwweerr
输出 #4
41
输入 #5
6 3 14 18 9 19 2 15 cccccc
输出 #5
52
输入 #6
2 1 10 10 qq
输出 #6
10
In the first example you can choose hits with numbers $[1, 3, 4, 5, 6, 7]$ with the total damage $1 + 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 = 1010$ .
In the third example you can choose all hits expect the third one so the total damage is $2 + 4 + 3 + 1000 = 1009$ .
In the fourth example you can choose hits with numbers $[2, 3, 6, 8]$ . Only this way you can reach the maximum total damage $15 + 2 + 8 + 16 = 41$ .
In the fifth example you can choose only hits with numbers $[2, 4, 6]$ with the total damage $18 + 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 $10$ .
In the second example you can choose all hits so the total damage is $2 + 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 = 1009$ .
In the fourth example you can choose hits with numbers $[2, 3, 6, 8]$ . Only this way you can reach the maximum total damage $15 + 2 + 8 + 16 = 41$ .
In the fifth example you can choose only hits with numbers $[2, 4, 6]$ with the total damage $18 + 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 $10$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted