This is an O(n^2) algorithm, right? I guess it's ok because the number of ranges is bounded.