how to solve this problem ?

https://www.codechef.com/CDDU2022/problems/MINSIZE
I know that this problem can be solve using binary search but I don’t know how to write the check funtion for this. Can any one plz. help?

Check the following C++ implementation.

Accepted

thanks a lot