CC long challenges sept

https://www.codechef.com/viewsolution/37548042

i have firrst tring to implement the naive approach that will give 2^n time complexity that i know using subset generation.please give me some hint or logic to improve the solution.

Sorry this is an ongoing live challenge , we cannot answer before the contest ends.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.