#ABC140D. Face Produces Unhappiness

Face Produces Unhappiness

题目描述

There are NN people standing in a queue from west to east.

Given is a string SS of length NN representing the directions of the people. The ii-th person from the west is facing west if the ii-th character of SS is L, and east if that character of SS is R.

A person is happy if the person in front of him/her is facing the same direction. If no person is standing in front of a person, however, he/she is not happy.

You can perform the following operation any number of times between 00 and KK (inclusive):

Operation: Choose integers ll and rr such that 1≤l≤r≤N1 \leq l \leq r \leq N, and rotate by 180180 degrees the part of the queue: the ll-th, (l+1)(l+1)-th, ......, rr-th persons. That is, for each i=0,1,...,r−li = 0, 1, ..., r-l, the (l+i)(l + i)-th person from the west will stand the (r−i)(r - i)-th from the west after the operation, facing east if he/she is facing west now, and vice versa.

What is the maximum possible number of happy people you can have?

有 NN 人从西向东排队。

给定长度为 NN 的字符串 SS 表示这些人的方向。如果 SS 的 ii 个字符是 L,那么从西边走来的 ii 个人就面向西边;如果 SS 的那个字符是 R,那么从东边走来的 ii 个人就面向东边。

如果一个人面前的人面向同一个方向,那么他/她就是快乐的。但是,如果一个人的前面没有人站着,他/她就不快乐。

您可以在 00 和 KK (含)之间任意多次执行以下操作:

操作:选择整数 ll 和 rr ,使得 1≤l≤r≤N1 \leq l \leq r \leq N ,并将队列中的部分旋转 180180 度:第 ll 个人,第 (l+1)(l+1) 个人, ...... ,第 rr 个人。也就是说,对于每一个 i=0,1,...,r−li = 0, 1, ..., r-l ,从西边来的第 (l+i)(l + i) 个人在操作后将站在从西边来的第 (r−i)(r - i) 个人的位置,如果他/她现在朝西,则朝东,反之亦然。

你最多可以拥有多少个快乐的人呢?

输入格式

输入内容按以下格式标准输入:

NN KK
SS

输出格式

打印最多进行 KK 次操作后可能出现的最多快乐人数。

样例 #1

样例输入 #1

6 1
LRLRRL

样例输出 #1

3

样例 #2

样例输入 #2

13 3
LRRLRLRRLRLLR

样例输出 #2

9

样例 #3

样例输入 #3

10 1
LLLLLRRRRR

样例输出 #3

9

样例 #4

样例输入 #4

9 2
RRRLRLRLL

样例输出 #4

7

说明

数据规模与约定

  • NN 是满足 1≤N≤1051 \leq N \leq 10^5 的整数。
  • KK 是满足 1≤K≤1051 \leq K \leq 10^5 的整数。
  • ∣S∣=N|S| = N
  • SS 的每个字符都是 L 或 R。

样例 11 解释

如果我们选择 (l,r)=(2,5)(l, r) = (2, 5) ,我们就得到了LLLRLL,来自西方的第 22、 第 33 和第 66 个人都很高兴。