#P15879. [ICPC 2026 NAC] Evil Judges
[ICPC 2026 NAC] Evil Judges
Description
The evil judges preparing the ICPC problem sets are tired of seeing the talented contestants AC their problems and AK ("all kill") their problem sets. They have grown so tired of this that they've started to dislike any strings where or appear as subsequences. The judges just found a string consisting of only the characters , , and and are determined to destroy these subsequences!
In one operation, the judges are able to swap two adjacent characters in the string . To be more precise, the judges may choose an index () and swap and . The judges are very busy and don't have much time, so they can only do this operation up to times (independently choosing an index each time).
The judges' goal is to minimize the number of subsequences () that are or . Help them calculate the number of and subsequences that remain within after the judges perform an optimal sequence of up to swap operations.
Input Format
The first line of input contains the string . The string consists only of the characters , , and .
The second line contains an integer , the maximum number of swaps the judges can perform.
Output Format
Print the minimum total number of and subsequences that remain in after an optimal sequence of at most swap operations.
ACAACCAK
5
6
CCKKAKCKCK
1000000000
0
AAAAAAAAACCCCCCCCC
13
68
Hint
Explanation of Sample Input 1
In Sample Input 1, the string initially has seven different subsequences and four different subsequences. One optimal choice of five swaps yields the new string which only has three subsequences and three subsequences left.
京公网安备 11011102002149号