|
1 | 1 | # 1792. Maximum Average Pass Ratio [Rating: 1818.00] |
2 | 2 |
|
3 | | -There is a school that has classes of students and each class will be having a final exam. You are given a 2D integer array `classes`, where `classes[i] = [passi, totali]`. You know beforehand that in the `ith`class, there are `totali` total students, but only `passi` number of students will pass the exam. |
| 3 | +<p>There is a school that has classes of students and each class will be having a final exam. You are given a 2D integer array <code>classes</code>, where <code>classes[i] = [pass<sub>i</sub>, total<sub>i</sub>]</code>. You know beforehand that in the <code>i<sup>th</sup></code> class, there are <code>total<sub>i</sub></code> total students, but only <code>pass<sub>i</sub></code> number of students will pass the exam.</p> |
4 | 4 |
|
5 | | -You are also given an integer `extraStudents`. There are another `extraStudents` brilliant students that are **guaranteed** to pass the exam of any class they are assigned to. You want to assign each of the `extraStudents` students to a class in a way that **maximizes** the **average** pass ratio across **all** the classes. |
| 5 | +<p>You are also given an integer <code>extraStudents</code>. There are another <code>extraStudents</code> brilliant students that are <strong>guaranteed</strong> to pass the exam of any class they are assigned to. You want to assign each of the <code>extraStudents</code> students to a class in a way that <strong>maximizes</strong> the <strong>average</strong> pass ratio across <strong>all</strong> the classes.</p> |
6 | 6 |
|
7 | | -The **pass ratio** of a class is equal to the number of students of the class that will pass the exam divided by the total number of students of the class. The **average pass ratio** is the sum of pass ratios of all the classes divided by the number of the classes. |
| 7 | +<p>The <strong>pass ratio</strong> of a class is equal to the number of students of the class that will pass the exam divided by the total number of students of the class. The <strong>average pass ratio</strong> is the sum of pass ratios of all the classes divided by the number of the classes.</p> |
8 | 8 |
|
9 | | -Return *the **maximum** possible average pass ratio after assigning the* `extraStudents` *students.* Answers within 10<sup>-5</sup> of the actual answer will be accepted. |
| 9 | +<p>Return <em>the <strong>maximum</strong> possible average pass ratio after assigning the </em><code>extraStudents</code><em> students. </em>Answers within <code>10<sup>-5</sup></code> of the actual answer will be accepted.</p> |
10 | 10 |
|
11 | | - |
| 11 | +<p> </p> |
| 12 | +<p><strong class="example">Example 1:</strong></p> |
12 | 13 |
|
13 | | -**Example 1:** |
| 14 | +<pre> |
| 15 | +<strong>Input:</strong> classes = [[1,2],[3,5],[2,2]], <code>extraStudents</code> = 2 |
| 16 | +<strong>Output:</strong> 0.78333 |
| 17 | +<strong>Explanation:</strong> 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. |
| 18 | +</pre> |
14 | 19 |
|
15 | | -``` |
16 | | -Input: classes = [[1,2],[3,5],[2,2]], extraStudents = 2 |
17 | | -Output: 0.78333 |
18 | | -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. |
19 | | -``` |
| 20 | +<p><strong class="example">Example 2:</strong></p> |
20 | 21 |
|
21 | | -**Example 2:** |
| 22 | +<pre> |
| 23 | +<strong>Input:</strong> classes = [[2,4],[3,9],[4,5],[2,10]], <code>extraStudents</code> = 4 |
| 24 | +<strong>Output:</strong> 0.53485 |
| 25 | +</pre> |
22 | 26 |
|
23 | | -``` |
24 | | -Input: classes = [[2,4],[3,9],[4,5],[2,10]], extraStudents = 4 |
25 | | -Output: 0.53485 |
26 | | -``` |
27 | | - |
28 | | - |
29 | | - |
30 | | -**Constraints:** |
31 | | - |
32 | | -- 1 <= classes.length <= 10<sup>5</sup> |
33 | | -- `classes[i].length == 2` |
34 | | -- 1 <= passi <= totali <= 10<sup>5</sup> |
35 | | -- 1 <= extraStudents <= 10<sup>5</sup> |
| 27 | +<p> </p> |
| 28 | +<p><strong>Constraints:</strong></p> |
36 | 29 |
|
| 30 | +<ul> |
| 31 | + <li><code>1 <= classes.length <= 10<sup>5</sup></code></li> |
| 32 | + <li><code>classes[i].length == 2</code></li> |
| 33 | + <li><code>1 <= pass<sub>i</sub> <= total<sub>i</sub> <= 10<sup>5</sup></code></li> |
| 34 | + <li><code>1 <= extraStudents <= 10<sup>5</sup></code></li> |
| 35 | +</ul> |
0 commit comments