P28797 [洛谷] [COI2012] TRAMPOLIN
提高+
题目描述

Problem Background

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

Problem Description

Specifically, he selects a sequence of N skyscrapers, numbered from 1 to N from left to right. He initially stands on the K-th skyscraper. Unfortunately, his abilities are limited, so he can only jump to adjacent skyscrapers, but only those whose heights are no greater than the height of his current skyscraper. However, he has trampolines on some skyscrapers, from which he can jump to any other skyscraper, regardless of height or location. Determine the maximum number of different skyscrapers he can jump to, starting from the K-th skyscraper. If a skyscraper is visited multiple times, it is only counted once. The K-th skyscraper is also counted, regardless of whether we return to it.

Input Format

The first line contains two numbers N and K (3 ≤ N ≤ 300,000, 1 ≤ K ≤ N), representing the total number of skyscrapers and the starting skyscraper.
The second line contains N numbers, each less than 10^6, representing the heights of the skyscrapers from left to right.
The third line contains N characters, either '.' or 'T'. If the i-th character is 'T', it indicates that there is a trampoline on the i-th skyscraper.

Output Format

A single number indicating the maximum number of skyscrapers that can be reached.

Sample Input and Output

Sample Input #1

6 4
12 16 16 16 14 14
.T....

Sample Output #1

5

Sample Input #2

10 1
10 7 3 1 1 9 8 2 4 10
..T..T....

Sample Output #2

7

Notes

The path for Sample 2 is as follows:
1 –> 2 –> 3 –> 6 –> 10 –> 9 –> 8.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
6 4 12 16 16 16 14 14 .T....
样例输出
5