SPP , Last test case fails

What’s wrong in my code ? it fails for last test case!!

link:

@beastaman96,
Is it giving TLE or WA…?

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.

its giving WA. I am still not clear what is wrong in the code.

@beastaman96,
Here, you can use this code to check yours, it uses the same approach your code does.
Also, maybe ones check whether it should be k or k+1 in the loops you have used.