Help needed, Codeforces EDU (two pointers)

Problem link
This is my approach

Code
I am getting WA on test case 4, please help me to find out what’s wrong in my solution