Kindly help me find the mistake in my code

Modified Code

Your Mistake:

if(a[i]+sum>mid){

            no_students++;

            **sum=a[i];**// you forgot this statement

            if(no_students>m){

                return false;
            }

now it is passing all testcases