if each girl gets x milliliters of water, then each boy gets 2x milliliters of water. In the other words, each boy should get two times more 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 two integers, n and w (1?≤?n?≤?105, 1?≤?w?≤?109) — the number of Pasha's friends that are boys (equal to the number of Pasha's friends that are girls) and the capacity of Pasha's teapot in milliliters.
The second line of the input contains the sequence of integers ai (1?≤?ai?≤?109, 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 that Pasha can pour to his friends without violating the given conditions. Your answer will be considered correct if its absolute or relative error doesn't exceed 10?-?6.
Sample test(s) 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
Note Pasha also has candies that he is going to give to girls but that is another task...
?
直接贪心,注意容积w
?
?
?
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std; #define For(i,n) for(int i=1;i<=n;i++) #define Fork(i,k,n) for(int i=k;i<=n;i++) #define Rep(i,n) for(int i=0;i
=0;i--) #define Forp(x) for(int p=pre[x];p;p=next[p]) #define Forpiter(x) for(int &p=iter[x];p;p=next[p]) #define Lson (x<<1) #define Rson ((x<<1)+1) #define MEM(a) memset(a,0,sizeof(a)); #define MEMI(a) memset(a,127,sizeof(a)); #define MEMi(a) memset(a,128,sizeof(a)); #define INF (2139062143) #define F (100000007) #define eps (1e-8) #define MAXN (1000000+10) typedef long long ll; ll mul(ll a,ll b){return (a*b)%F;} ll add(ll a,ll b){return (a+b)%F;} ll sub(ll a,ll b){return (a-b+(a-b)/F*F+F)%F;} void upd(ll &a,ll b){a=(a%F+b%F)%F;} int n,w; int a[MAXN]; int main() { // freopen(B.in,r,stdin); // freopen(.out,w,stdout); cin>>n>>w; For(i,2*n) scanf(%d,&a[i]); sort(a+1,a+1+2*n); double ans=min((double)a[1],(double)(a[1+n])/(double)2.0); printf(%.8lf ,min((double)w,ans*3*(double)n) ); return 0; }
?
?
?
?
?