307866: CF1427B. Chess Cheater
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Chess Cheater
题意翻译
你参加了 $n$ 场比赛,每场游戏要么赢要么输(无平局)。比赛的计分规则如下: 1. 输掉一场比赛得$0$分。 2. 赢得一场比赛时,若上一局比赛也赢了,则这场比赛得$2$分,否则得$1$分。 3. 如果第一局比赛就赢了,得$1$分。 输赢结果由一段长为 $n$ 的字符串表示。如果第 $i$ 个字符为 $W$ ,则表示第 $i$ 场比赛胜利;反之,如果第 $i$ 个字符为 $L$ ,则表示第 $i$ 场比赛输了。 你可以更改这个字符串中最多 $k$ 个字符。最大化获得的分数。题目描述
You like playing chess tournaments online. In your last tournament you played $ n $ games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get $ 0 $ points. When you win you get $ 1 $ or $ 2 $ points: if you have won also the previous game you get $ 2 $ points, otherwise you get $ 1 $ point. If you win the very first game of the tournament you get $ 1 $ point (since there is not a "previous game"). The outcomes of the $ n $ games are represented by a string $ s $ of length $ n $ : the $ i $ -th character of $ s $ is W if you have won the $ i $ -th game, while it is L if you have lost the $ i $ -th game. After the tournament, you notice a bug on the website that allows you to change the outcome of at most $ k $ of your games (meaning that at most $ k $ times you can change some symbol L to W, or W to L). Since your only goal is to improve your chess rating, you decide to cheat and use the bug. Compute the maximum score you can get by cheating in the optimal way.输入输出格式
输入格式
Each test contains multiple test cases. The first line contains an integer $ t $ ( $ 1\le t \le 20,000 $ ) — the number of test cases. The description of the test cases follows. The first line of each testcase contains two integers $ n, k $ ( $ 1\le n\le 100,000 $ , $ 0\le k\le n $ ) – the number of games played and the number of outcomes that you can change. The second line contains a string $ s $ of length $ n $ containing only the characters W and L. If you have won the $ i $ -th game then $ s_i=\, $ W, if you have lost the $ i $ -th game then $ s_i=\, $ L. It is guaranteed that the sum of $ n $ over all testcases does not exceed $ 200,000 $ .
输出格式
For each testcase, print a single integer – the maximum score you can get by cheating in the optimal way.
输入输出样例
输入样例 #1
8
5 2
WLWLL
6 5
LLLWWL
7 1
LWLWLWL
15 5
WWWLLLWWWLLLWWW
40 7
LLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL
1 0
L
1 1
L
6 1
WLLWLW
输出样例 #1
7
11
6
26
46
0
1
6