luogu#P4786. [BalkanOI 2018] Election
[BalkanOI 2018] Election
Problem Description
Translated from BalkanOI 2018 Day 1 T1 “Election”.
There is a string of length , consisting only of the two letters C and T.
Now there are queries. Each query contains two integers and , meaning: let the new string be . What is the minimum number of characters that must be deleted from to ensure that, for every prefix and every suffix of , the number of C is not less than the number of T?
Input Format
The first line contains an integer .
The second line contains a string of length .
The third line contains an integer .
In the next lines, each line contains two integers and , representing one query.
Output Format
For each query, output one line: the minimum number of characters that must be deleted from to satisfy the requirement in the statement.
11
CCCTTTTTTCC
3
1 11
4 9
1 6
4
6
3
Hint
Sample Explanation
Query 1: CCCTTTTTTCC.
Query 2: TTTTTT.
Query 3: CCCTTT.
Subtask #1 (28 points): .
Subtask #2 (54 points): .
Subtask #3 (18 points): .
Thanks to Planet6174 for providing the translation.
Translated by ChatGPT 5