An improved verson of Ballot, using binary search to find the value, O(n3logn)