#abc229g. G - Longest Y

G - Longest Y

Score : 600600 points

问题描述

给定一个由 Y. 组成的字符串 SS

你可以在 00KK 次(包含)之间对 SS 执行以下操作:

  • 交换 SS 中的两个相邻字符。

在执行操作后,SS 中连续 Ys 的最大可能数量是多少?

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Given is a string SS consisting of Y and ..

You can do the following operation on SS between 00 and KK times (inclusive).

  • Swap two adjacent characters in SS.

What is the maximum possible number of consecutive Ys in SS after the operations?

Constraints

  • 2S2×1052 \leq |S| \leq 2 \times 10^5
  • Each character of SS is Y or ..
  • 0K10120 \leq K \leq 10^{12}
  • KK is an integer.

Input

Input is given from Standard Input in the following format:

SS

KK

Output

Print the answer.

Sample Input 1

YY...Y.Y.Y.
2

Sample Output 1

3

After swapping the 66-th, 77-th characters, and 99-th, 1010-th characters, we have YY....YYY.., which has three consecutive Ys at 77-th through 99-th positions.
We cannot have four or more consecutive Ys, so the answer is 33.

Sample Input 2

YYYY....YYY
3

Sample Output 2

4

update @ 2024/3/10 10:01:53

}