import
java.util.*;
class
DescendingComparer<T
extends
Comparable<T> >
implements
Comparator<T> {
public
int
compare(T x, T y)
{
if
(x ==
null
) {
return
-
1
;
}
if
(y ==
null
) {
return
1
;
}
return
x.compareTo(y);
}
}
class
GFG {
static
double
change(
int
pass,
int
total)
{
double
currentPassRatio, newPassRatio;
double
increase;
currentPassRatio = ((
double
)pass) / total;
newPassRatio = ((
double
)(pass +
1
)) / (total +
1
);
increase = newPassRatio - currentPassRatio;
return
increase;
}
static
double
maximumAverage(List<List<Integer> > v,
int
M,
int
N)
{
double
sum =
0
;
double
increase, average;
PriorityQueue<Double> pq =
new
PriorityQueue<>(
new
DescendingComparer<Double>());
for
(
int
i =
0
; i < N; i++) {
increase
= change(v.get(i).get(
0
), v.get(i).get(
1
));
pq.add(increase);
average = v.get(i).get(
0
) *
1.0
/ (
1.0
* v.get(i).get(
1
));
sum += average;
}
while
(M >
0
) {
sum += pq.poll();
M--;
}
double
ans = sum / (
1.0
* N);
return
ans;
}
public
static
void
main(String[] args)
{
List<List<Integer> > V =
new
ArrayList<>();
V.add(Arrays.asList(
1
,
2
));
V.add(Arrays.asList(
3
,
5
));
V.add(Arrays.asList(
2
,
2
));
int
M =
2
;
int
N = V.size();
System.out.println(maximumAverage(V, M, N));
}
}