Just as an aside, if you had lazy lists (coming in perl6) and the appropriate
sort, the following should run in optimal O(X*log(N)) time, straight out of the box.
@topN = (sort @X)[0..($N-1)];
-- All code is 100% tested and functional unless otherwise noted.