We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5b48eec commit 032d374Copy full SHA for 032d374
1792-maximum-average-pass-ratio/1792-maximum-average-pass-ratio.java
@@ -0,0 +1,26 @@
1
+class Solution {
2
+ public double maxAverageRatio(int[][] classes, int k) {
3
+ double res=0;
4
+ PriorityQueue<int[]> pq = new PriorityQueue<>((x, y) -> {
5
+ double xDiff = (double)(x[0]+1)/(x[1]+1) - (double)x[0]/x[1];
6
+ double yDiff = (double)(y[0]+1)/(y[1]+1) - (double)y[0]/y[1];
7
+ return xDiff > yDiff? -1 : 1;
8
+ });
9
+
10
+ for(int[] c : classes){
11
+ pq.offer(c);
12
+ }
13
+ while(k-->0){
14
+ int[] c = pq.poll();
15
+ c[0]++;
16
+ c[1]++;
17
+ pq.add(c);
18
19
20
+ while(!pq.isEmpty()){
21
22
+ res += (double)c[0]/c[1];
23
24
+ return res/classes.length;
25
26
+}
0 commit comments