#1792
Maximum Average Pass Ratio
pupil · 510 · lc medium +27 · premium · verified · 74.1% accepted · 1,931 likes · top 84%
Description
A school has classes classes[i] = [passi, totali]. You have extraStudents guaranteed-to-pass students to assign. The pass ratio of class i is passi / totali. Assign to maximize the average pass ratio. Return the maximum. Answers within 10-5 are accepted.
Example 1:
Input: classes = [[1,2],[3,5],[2,2]], extraStudents = 2
Output: 0.78333
Explanation: You can assign the two extra students to the first class. The average pass ratio will be equal to (3/4 + 3/5 + 2/2) / 3 = 0.78333.
Example 2:
Input: classes = [[2,4],[3,9],[4,5],[2,10]], extraStudents = 4
Output: 0.53485
Code
1
2
3