#P14018. [ICPC 2024 Nanjing R] 左移 3
[ICPC 2024 Nanjing R] 左移 3
Description
Given a string of length , you can shift to the left for at most times (including zero times). Calculate the maximum number of nanjing substrings contained in the string after the operations.
More formally, let be the string obtained by shifting to the left times. That is, $f(S, d) = s_{(d+0)\bmod n}s_{(d+1)\bmod n}\cdots s_{(d+n-1)\bmod n}$. Let $g(f(S, d), l, r) = s_{(d+l)\bmod n}s_{(d+l+1)\bmod n}\cdots s_{(d+r)\bmod n}$. Let be the number of integer pairs such that and \texttt{nanjing}. Find an integer such that to maximize and output this maximized value.
Input Format
There are multiple test cases. The first line of the input contains an integer indicating the number of test cases. For each test case:
The first line contains two integers and (, ) indicating the length of the string and the maximum number of left shifts you can perform.
The second line contains a string of length . The string consists of lower-cased English letters.
It's guaranteed that the sum of of all test cases will not exceed .
Output Format
For each test case, output one line containing one integer, indicating the maximum number of nanjing substrings contained in the string.
4
21 10
jingicpcnanjingsuanan
21 0
jingicpcnanjingsuanan
21 3
nanjingnanjingnanjing
4 100
icpc
2
1
3
0
京公网安备 11011102002149号