Winning cb scholarship


please explain me the binary part , what exactly is happening here. i have commented the part to know


	public static long binarySearch(long n,long m,long x,long y) {
		long ans =0,s=0,e=n;//we are solving this problem using bs. our search space is(i.e the number of students) can be from 0 to n
		while(s<=e) {
			long mid =(s+e)/2;//calculate mid
            //check if you can provide scholarship to mid students
			if(possible(n,m,x,y,mid)) {//if you can store the value of mid in ans..and set your s to mid+1 as you need to maximize the number of students
				ans=Math.max(mid,ans);
				s=mid+1;
				
			}else {//if you cannot provide scholarship to mid students..you need to search your ans in s to mid-1
				e=mid-1;
			}
		}
		return ans;
		
	}