using namespace std;
int minreq=0,req=0;char S;
Please either format your code or link to your submission - the forum software has mangled it and it won’t compile!
Assuming this is your solution: it fails on the following testcase:
1 437 AAAAAPAPPAAAPAAAAPAAAAPPPPAAPAAPAAAAAPAPPPPPAAAPPPAPAAAAPAAPPAPPAAAAAAAAAAPAAAAAPAAPAAAAPPAAAPAAAAAAAAAAPAPPAPAAAAAAPPPAAPPAPAPPPAAAPPAPPAPAPAAAPAAPAPAAAAAAPPAAAAAPPPPAAAAAPAAAAAAAPPPAAAPAPAPAAPAPAAAAPPAPAAAAPPAPPAPPPAPPAPAPPAAPAAPPAPAPAAPAPPPAAPPPAPPPPAAPAAPAPAAAPPAAPAAPAAAPAAAAAAPAAAAPAAAPAAAAPAAAPAPPPPPPPAAPAAAPPAPAPAAPAPAPAPPAAAPAAAPAPPAPAPPAPPPPPAAPAPPAAPPPAAAPAAAAPPAAAAPPPAPAPAPPPAAAPAPAPAPAAAAPPAPPPPPPPAAAPPAAPAPPPAPAAPPPPPAAP
(the answer should be
why do you think it fails?
Like I am not able to find any errors in my code
That’s for you to find out - you’ve got a nice, 100%-reproducible testcase to work with