String window STL question

Please help me in this question. Any hint or something.

https://hack.codingblocks.com/app/contests/1202/363/problem

please read the editorial it gives a full idea of the question
editorial is in the solution tab