Skip to content

Commit f60319d

Browse files
committed
daily
1 parent 3e40d5e commit f60319d

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

my-submissions/m1782.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution:
2+
def maxAverageRatio(self, classes: List[List[int]], extraStudents: int) -> float:
3+
4+
# Min heap not including 100% ratios since
5+
# their ratios wouldn't change
6+
# (-1 * amount of ratio gain, total students, passing students)
7+
hp = [
8+
((passing / tot - (passing + 1) / (tot + 1)), tot, passing)
9+
for passing, tot in classes
10+
if tot != passing
11+
]
12+
heapify(hp)
13+
14+
while hp and extraStudents :
15+
_, tot, passing = heappop(hp)
16+
17+
tot += 1
18+
passing += 1
19+
heappush(hp, ((passing / tot - (passing + 1) / (tot + 1)), tot, passing))
20+
extraStudents -= 1
21+
22+
return (sum(passing / tot for _, tot, passing in hp) + (len(classes) - len(hp))) / len(classes)

my-submissions/m1792.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Very interesting question. Simple in terms of it being a greedy heap question, but facinating in terms of how it highlights how ratios change as you augment them.
2+
3+
I initially assumed that we'd simply be adding to the class that's denominator was the smallest since it'd have the largest ratio effect since smaller ratios are more sensitive.
4+
5+
I then thought that for ratios with equal denominators, you should apply it to the case with a smaller numerator since the larger case is more "stable" and would "gain" less since its existing numerator amount would "decrease" a more since the increased denominator also affects it.
6+
7+
Then I realized that this isn't always true so I adjusted the heap to be based on a precomputed heuristic that is the benefit of adding a excelling student to the given class directly. I'm curious as to the math and logical reasoning that causes this though! Will keep digging :D

0 commit comments

Comments
 (0)