Optimal Full Ranking from Pairwise Comparisons