O(n lg n) time solution to google code jams "Data Packing" problem