Skip to content

1792. Maximum Average Pass Ratio #957

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We can use a max-heap (priority queue). This is because we need to efficiently find the class that benefits the most (maximizes the change in pass ratio) when adding an extra student.

Approach:

  1. Understand the Gain Calculation:

    • When adding one student to a class, the change in the pass ratio can be calculated as:
      gain = (pass + 1)/(total + 1) - pass/total
    • The task is to maximize the sum of pass ratios across all classes by distributing extraStudents optimally.
  2. Use a Max-Heap:

    • For each class, calculate the initial gain and insert it into a max-heap along with the class details.
    • Each heap element is a tuple: [negative gain, pass, total]. (We use a negative gain because PHP's SplPriori…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@kovatz
Comment options

kovatz Dec 15, 2024
Collaborator

@mah-shamim
Comment options

mah-shamim Dec 15, 2024
Maintainer Author

Answer selected by kovatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants