P26802 [AtCoder] Delete Balls
NOI
题目描述

Problem Description

Given a string \( S \) of length \( N \) consisting of characters R, B, and W.

There are \( N \) balls arranged in a row, where the color of the \( i \)-th ball from the left is red if the \( i \)-th character of \( S \) is R, blue if it is B, and white if it is W.

Initially, you will repaint all white balls either red or blue. After that, you can perform the following operation as many times as possible:

  • Select a contiguous sequence of balls of length \( r + b \) consisting of \( r \) red balls and \( b \) blue balls, and remove the entire sequence. Then, compact the remaining balls to maintain their order.

Determine the maximum number of operations that can be performed by repainting the balls appropriately and performing the operations correctly.

Input Format

The input is given from the standard input in the following format:

\( N \) \( r \) \( b \) \( S \)

Output Format

Output the maximum number of operations.

Sample Input and Output

Sample Input #1

4 1 1
BBWR

Sample Output #1

2

Sample Input #2

6 2 1
RBBBWB

Sample Output #2

0

Sample Input #3

13 3 3
WWWWWWWWWWWWW

Sample Output #3

2

Notes/Hints

Constraints

  • \( 1 \leq N \leq 2 \times 10^5 \)
  • \( 1 \leq r, b \)
  • \( r + b \leq N \)
  • \( N, r, b \) are integers
  • \( S \) is a string of length \( N \) consisting of R, B, and W

Sample Explanation 1

First, repaint the 3rd white ball from the left to red. In the 1st operation, select the contiguous subsequence consisting of the 2nd blue ball and the 3rd red ball from the left and remove it. In the 2nd operation, select the contiguous subsequence consisting of the 1st blue ball and the 2nd red ball from the left and remove it. Thus, 2 operations can be performed. It is not possible to perform more than 3 operations with any procedure, so the answer is 2.

Sample Explanation 2

The subsequence to be removed must be contiguous.

Sample Explanation 3

Note that not all balls need to be painted the same color.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
4 1 1 BBWR
样例输出
2