Books allocation problem

What is the need to allocate min(ans , mid) to ans?
Isn’t it obvious that the value of next mid will always be smaller than ans? so, just say ans=mid

@shreyaanand2908
No it is not necessary to write mid(ans,mid)