P4611 [COI 2012] TRAMPOLIN

Background

There are many superheroes: Batman, Spider-Man, Superman, etc. Among them, there is one called Niu. Today he wants to imitate Spider-Man, so he chose a row of tall skyscrapers to jump across.

Description

Specifically, he chose a sequence of $N$ skyscrapers, numbered from $1$ to $N$ from left to right. He initially stays on the $K$-th skyscraper. Unfortunately, his ability is limited, so he can only jump left or right to an adjacent skyscraper, and only to a skyscraper whose height is not greater than the height of his current skyscraper. However, some skyscrapers have trampolines. From such a skyscraper, he can jump to any other skyscraper, no matter how tall it is and no matter where it is. Find the maximum number of distinct skyscrapers he can reach starting from the $K$-th skyscraper. If a skyscraper is visited multiple times, it is counted only once. Skyscraper $K$ is also counted, whether or not he returns to it.

Input Format

The first line contains two integers $N$ and $K$ ($3 \le N \le 300\,000$, $1 \le K \le N$), representing the total number of skyscrapers and the starting skyscraper. The second line contains $N$ integers, each less than $10^6$, describing the heights of the skyscrapers from left to right. The third line contains $N$ characters, `.` or `T`. If the $i$-th character is `T`, it means there is a trampoline on the $i$-th skyscraper.

Output Format

Output one integer, the maximum number of skyscrapers that can be reached.

Explanation/Hint

The route for Sample 2 is as follows: $1 \to 2 \to 3 \to 6 \to 10 \to 9 \to 8$. Translated by ChatGPT 5