import
java.io.*;
import
java.util.*;
class
Pair {
double
first, second;
Pair(
double
first,
double
second)
{
this
.first = first;
this
.second = second;
}
}
class
GFG {
static
class
ComparePairs
implements
Comparator<Pair> {
public
int
compare(Pair p1, Pair p2)
{
double
a = p1.first, b = p1.second;
double
c = p2.first, d = p2.second;
double
val1 =
0
, val2 =
0
;
val1 = a / b;
val2 = c / d;
if
(val1 > val2) {
return
-
1
;
}
else
if
(val1 < val2) {
return
1
;
}
else
{
return
0
;
}
}
}
static
double
maximumProfit(
int
[] A,
int
[] B,
int
N,
double
W)
{
List<Pair> V =
new
ArrayList<Pair>();
for
(
int
i =
0
; i < N; i++) {
double
temp = (
double
)Math.sqrt(A[i]);
if
(temp * temp == A[i]) {
continue
;
}
V.add(
new
Pair(B[i], A[i]));
}
V.sort(
new
ComparePairs());
double
profit =
0.00
;
for
(
int
i =
0
; i < V.size(); i++) {
if
(V.get(i).second <= W) {
profit += V.get(i).first;
W -= V.get(i).second;
}
else
{
profit += V.get(i).first
* ((
double
)W
/ (
double
)V.get(i).second);
break
;
}
}
return
profit;
}
public
static
void
main(String[] args)
{
int
N =
3
;
double
W =
10
;
int
[] A = {
4
,
5
,
7
};
int
[] B = {
8
,
5
,
4
};
System.out.println(String.format(
"%.5f"
, maximumProfit(A, B, N, W)));
}
}