#P1136. 迎接仪式
迎接仪式
Description
Leader LHX is coming to City X to guide OI studies. To welcome the Leader (jiaozhu), along a road, a group of Orzer wearing T-shirts stand on both sides of the road, with big characters printed on each shirt. On one side, the Orzer spell out “欢迎欢迎欢迎欢迎……” in order, but the leader of the group suddenly notices that the Orzer on the other side, who wear the characters “教” and “主,” look less harmonious.
To describe this disharmony simply, we use j to replace “教” and z to replace “主.” A sequence composed of j and z then describes the current lineup. To make it as pleasing as possible for the Leader, you must adjust the lineup to maximize the number of jz substrings. In each adjustment, you can swap any two people at any positions, that is, swap the two letters at any positions in the sequence. Since the Leader is arriving soon, there is time for at most adjustments (you may also perform fewer than ), so this problem is assigned to you.
Input Format
The first line contains two positive integers , denoting the length of the sequence and the maximum number of swaps.
The second line contains a string of length , consisting only of the letters j and z, describing the sequence.
Output Format
Output a non-negative integer: after at most swaps, the maximum possible number of jz substrings.
5 2
zzzjj
2
Hint
【Sample Explanation】
First, swap the z at position 1 with the j at position 4 to get jzzzj.
Second, swap the z at position 4 with the j at position 5 to get jzzjz.
The final string has jz substrings.
【Constraints】
For of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号