I was attempting this question https://www.codechef.com/problems/KNPSK getting WA for the same. What’s wrong with the following solution.
https://www.codechef.com/viewsolution/9144714
EDIT:-
I finally came up with this (https://www.codechef.com/viewsolution/9425592) solution covering all the cases