Making PPC
Time limit1sMemory limit1024 MB
Given a string of C and P characters and at most K swaps, maximize the number of PPC subsequences (P, then P, then C, in order).
- Level
Medium5 of 10
- Topics
- Greedy, Two pointers, String
- Solved
- No attempts yet
Problem
Phoenix has a string that he treasures. has length and consists only of the uppercase letters C and P. The -th character of is written .
Phoenix wants to decorate the venue of a contest with for the teams taking part in PPC. Before the contest, Phoenix can perform the following operation on at most times.
- Choose two integers and with , and swap and .
Phoenix's goal is to make the finished string contain as many PPC subsequences as possible. A PPC subsequence is a triple with , P, and C.
Input
The first line contains the length of the string and the maximum number of operations , separated by a space. ()
The second line contains the string of length . It is guaranteed that consists only of the uppercase letters C and P.
Output
Print the maximum number of PPC subsequences that Phoenix can make.