This commit is contained in:
parent
bac9beaa68
commit
119dc4617d
1 changed files with 26 additions and 0 deletions
26
medium/maximum_average_pass_ratio.py
Normal file
26
medium/maximum_average_pass_ratio.py
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
# https://leetcode.com/problems/maximum-average-pass-ratio
|
||||||
|
|
||||||
|
from typing import List
|
||||||
|
from queue import PriorityQueue
|
||||||
|
|
||||||
|
class Solution:
|
||||||
|
def maxAverageRatio(self, classes: List[List[int]], extraStudents: int) -> float:
|
||||||
|
def to_priority(clas):
|
||||||
|
return -abs((clas[0] / clas[1]) - ((clas[0] + 1) / (clas[1] + 1)))
|
||||||
|
|
||||||
|
q = PriorityQueue()
|
||||||
|
for i in range(len(classes)):
|
||||||
|
v = to_priority(classes[i])
|
||||||
|
q.put((v, i))
|
||||||
|
for i in range(extraStudents):
|
||||||
|
(_, index) = q.get()
|
||||||
|
classes[index][0] += 1
|
||||||
|
classes[index][1] += 1
|
||||||
|
q.put((to_priority(classes[index]), index))
|
||||||
|
result = 0
|
||||||
|
for i in range(len(classes)):
|
||||||
|
result += (classes[i][0] / classes[i][1])
|
||||||
|
return result / len(classes)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue