Description
Pasha decided to invite he friends to a tea party. For that occasion, he had a large teapot with the capacity of W milliliters and 2n tea cups, EAC H Cup is for one of Pasha ' s friends. The I-th Cup can hold at most ai milliliters of water.
It turned out that among Pasha ' s friends there is exactly n boys and exactly n Girls and All of them is going to come to the tea Party. To the Everyone, Pasha decided to pour the water for the tea as follows:
- Pasha can boil the teapot exactly once by pouring there at most w milliliters of water;
- Pasha pours the same amount of water to each girl;
- Pasha pours the same amount of water to each boy;
- If each girl gets x milliliters of water and then each boy gets 2x milliliters of water.
In the other words, each of the boy should get and the water than each girl does.
Pasha is very kind and polite, so he wants to maximize the total amount of the water that he pours to his friends. Your task is to help him and determine the optimum distribution of cups between Pasha ' s friends.
Input
The first line of the input contains the integers, n and w (1≤ n ≤105, 1 ≤ w ≤109)-the number of Pasha ' s friends that is boys (equal to the number of Pasha ' s friends that is GIR LS) and the capacity of Pasha ' s teapot in milliliters.
The second line of the input contains the sequence of integers ai (1≤ a i ≤10 9, 1≤ i ≤2n)-the capacities of Pasha ' s tea cups in milliliters.
Output
Print a single real number-the maximum total amount of water in milliliters so Pasha can pour to his friends without V Iolating the given conditions. Your answer would be a considered correct if its absolute or relative error doesn ' t exceed -6.
Sample Input
Input
2 4
1 1 1 1
Output
3
Input
3 18
4 4 4 2 2 2
Output
18
Input
1 5
2 3
Output
4.5
Hint
Pasha also have candies that he's going to give to girls and that's is another task ...
//greedy first want the best results all girls pour girls the smallest cup so boys pour boys the smallest cup#include <stdio.h>#include<algorithm>using namespacestd;intMain () {intn,w,a[200010]; Doublep; while(SCANF ("%d%d", &n,&w)! =EOF) { for(intI=0; i<2*n; i++) {scanf ("%d",&A[i]); } sort (A,a+2*N); if(a[0]>a[n]/2)//when the girl's minimum cup is more than half the boy's smallest cupp=a[n]/2.0;//take the boy's minimum Cup as a reference ElseP=a[0]*1.0;//Otherwise, take the girl as the reference if(p*3*n>W) printf ("%d\n", W);//if the total is exceeded Elseprintf ("%lf\n", p*3*N);//Total } return 0;}
Cf-pasha and Tea (greedy 6)