Longest Y

AtCoder
IDabc229_g
Time2000ms
Memory256MB
Difficulty
Given is a string $S$ consisting of `Y` and `.`. You can do the following operation on $S$ between $0$ and $K$ times (inclusive). * Swap two adjacent characters in $S$. What is the maximum possible number of consecutive `Y`s in $S$ after the operations? ## Constraints * $2 \leq |S| \leq 2 \times 10^5$ * Each character of $S$ is `Y` or `.`. * $0 \leq K \leq 10^{12}$ * $K$ is an integer. ## Input Input is given from Standard Input in the following format: $S$ $K$ [samples]
Samples
Input #1
YY...Y.Y.Y.
2
Output #1
3

After swapping the $6$\-th, $7$\-th characters, and $9$\-th, $10$\-th characters, we have `YY....YYY..`, which has three consecutive `Y`s at $7$\-th through $9$\-th positions.  
We cannot have four or more consecutive `Y`s, so the answer is $3$.
Input #2
YYYY....YYY
3
Output #2
4
API Response (JSON)
{
  "problem": {
    "name": "Longest Y",
    "description": {
      "content": "Given is a string $S$ consisting of `Y` and `.`. You can do the following operation on $S$ between $0$ and $K$ times (inclusive). *   Swap two adjacent characters in $S$. What is the maximum possibl",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc229_g"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Given is a string $S$ consisting of `Y` and `.`.\nYou can do the following operation on $S$ between $0$ and $K$ times (inclusive).\n\n*   Swap two adjacent characters in $S$.\n\nWhat is the maximum possibl...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments