0
点赞
收藏
分享

微信扫一扫

CF 557B(Pasha and Tea-贪心)



B. Pasha and Tea



time limit per test



memory limit per test



input



output



w milliliters and 2n tea cups, each cup is for one of Pasha's friends. The i-th cup can hold at most ai

n boys and exactly n

  • w
  • Pasha pours the same amount of water to each girl;
  • Pasha pours the same amount of water to each boy;
  • xmilliliters of water, then each boy gets 2x

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



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.

ai (1 ≤ ai ≤ 109, 1 ≤ i ≤ 2n) — the capacities of Pasha's tea cups in milliliters.



Output



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<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
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<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;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\n",min((double)w,ans*3*(double)n) );


return 0;
}






举报

相关推荐

0 条评论