CF1107C.Brutality

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 aia_i units of damage to the opponent's character. To perform the ii-th hit you have to press the button sis_i 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 aia_i 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.

你正在玩一款新出的著名格斗游戏:《真人快打XII》。你需要对对手角色施放“残忍终结技”(brutality)。

你使用的是新一代游戏主机,因此你的游戏手柄上有 2626 个按键,每个按键上印有一个小写拉丁字母,范围为 'a' 到 'z',且所有按键上的字母两两互不相同。

你被给定一个连击序列,其中第 ii 次连击会对对手角色造成 aia_i 点伤害。要执行第 ii 次连击,你必须按下游戏手柄上的按钮 sis_i。连击按序号从 11 编号至 nn。

已知:若某个按钮被连续按下超过 kk 次,该按钮就会损坏。你非常珍惜自己的游戏手柄,因此不希望任何按键损坏。

要成功施放残忍终结技,你必须命中给定序列中的部分连击。你可以跳过任意连击,但严禁改变原始序列中连击的顺序。总伤害值等于所有未被跳过的连击所对应的 aia_i 值之和。

注意:如果你跳过了某次连击,则对应按钮的连续按压计数器不会重置。

你的任务是:通过跳过部分连击,在不损坏任何按键的前提下,使对对手角色造成的总伤害值最大化。

输入格式

The first line of the input contains two integers nn and kk (1≤k≤n≤2⋅1051 \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 nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1091 \le a_i \le 10^9), where aia_i 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).

输入的第一行包含两个整数 nn 和 kk(1≤k≤n≤2⋅1051 \le k \le n \le 2 \cdot 10^5)—— 分别表示攻击次数以及你连续按同一按键的最大次数。

输入的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1091 \le a_i \le 10^9),其中 aia_i 表示第 ii 次攻击的伤害值。

输入的第三行包含一个由恰好 nn 个小写拉丁字母组成的字符串 ss —— 表示攻击序列(每个字符即为执行对应攻击所需按下的按键上的字母)。

输出格式

Print one integer dmgdmg — the maximum possible damage to the opponent's character you can deal without breaking your gamepad buttons.

输出一个整数 dmgdmg —— 在不损坏游戏手柄按钮的前提下,你能对对手角色造成的最大伤害值。

输入输出样例

  • 输入#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][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.

在第一个例子中,你可以选择编号为 [1,3,4,5,6,7][1, 3, 4, 5, 6, 7] 的攻击,总伤害为 1+16+18+7+2+10=541 + 16 + 18 + 7 + 2 + 10 = 54。

在第二个例子中,你可以选择所有攻击,总伤害为 2+4+1+3+1000=10102 + 4 + 1 + 3 + 1000 = 1010。

在第三个例子中,你可以选择除第三个攻击外的所有攻击,总伤害为 2+4+3+1000=10092 + 4 + 3 + 1000 = 1009。

在第四个例子中,你可以选择编号为 [2,3,6,8][2, 3, 6, 8] 的攻击。只有这种方式可以达到最大总伤害 15+2+8+16=4115 + 2 + 8 + 16 = 41。

在第五个例子中,你只能选择编号为 [2,4,6][2, 4, 6] 的攻击,总伤害为 18+19+15=5218 + 19 + 15 = 52。

在第六个例子中,你可以更改第一个攻击或第二个攻击(两者均可),总伤害为 1010。

输入解题思路,AI测评打分。不知道怎么写?

首页