AmazonOA #46
Get Maximum Profit (Trade with K-Run Cap)
估计简单可在线判题
Within each original maximal run of identical consecutive characters in the command string, at most k commands can be executed, and other commands may be skipped; choices do not change the original runs. Every command has a positive profit; find the maximum total profit.
输入格式
The first line contains n k (1≤k≤n≤200000), the second line contains a lowercase command string of length n, and the third line contains n profits (1..10⁹).
输出格式
Output a single integer answer.
样例 1
输入:
5 2
abbba
1 4 2 10 3
输出:
18
样例 2
输入:
3 1
aaa
1 2 3
输出:
3
样例 3
输入:
3 1
aba
1 2 3
输出:
6
样例说明
Example 1: the a at each end forms its own run, giving profits 1+3; the middle bbb takes 10 and 4, for a total of 18. Example 2: the only run can take at most 1 command, so choose profit 3. Example 3: each of the three original runs has only one command and all can be executed, for a total of 6.