#P4611. [COI 2012] TRAMPOLIN
[COI 2012] TRAMPOLIN
Description
Specifically, he chose a sequence of skyscrapers, numbered from to from left to right. He initially stays on the -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 -th skyscraper. If a skyscraper is visited multiple times, it is counted only once. Skyscraper is also counted, whether or not he returns to it.
Input Format
The first line contains two integers and (, ), representing the total number of skyscrapers and the starting skyscraper.
The second line contains integers, each less than , describing the heights of the skyscrapers from left to right.
The third line contains characters, . or T. If the -th character is T, it means there is a trampoline on the -th skyscraper.
Output Format
Output one integer, the maximum number of skyscrapers that can be reached.
6 4
12 16 16 16 14 14
.T....
5
10 1
10 7 3 1 1 9 8 2 4 10
..T..T....
7
Hint
The route for Sample 2 is as follows: .
Translated by ChatGPT 5
京公网安备 11011102002149号