Optimized max flags bound to sqrt(N)