CSES Apartments help

I attempted the CSES Apartments problem and here is my code in java. I’ve used the two pointer approach but still I’m getting a timeout in one of the testcases. Plz tell me what’s wrong.