CodeForces

来源:互联网 发布:java加密软件 编辑:程序博客网 时间:2024/06/11 11:00

Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity ofw milliliters and 2n tea cups, each cup is for one of Pasha's friends. Thei-th cup can hold at most ai milliliters of water.

It turned out that among Pasha's friends there are exactly n boys and exactly n girls and all of them are going to come to the tea party. To please 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, then each boy gets2x 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 andw (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 exceed10 - 6.

Example
Input
2 41 1 1 1
Output
3
Input
3 184 4 4 2 2 2
Output
18
Input
1 52 3
Output
4.5

题目大意就是给2n个杯子,w体积的水,每个杯子都有它的体积,女生男生各n人,一人一个杯子,所有女生喝的水量相同,所有男生喝的水量相同,女生喝的水是男生的一半,问w体积的水倒给这些杯子,最多可以用掉多少体积的水

显然就是将杯子的体积都排序,大杯子给男生,小杯子给女生,然后计算男生或女生喝的水的水量

当小杯子中最小的那个的体积的  两倍  比大杯子中最小的那个的体积要小的时候,说明女生喝的水的水量最大就是该小杯子的体积

当小杯子中最小的那个的体积的  两倍  比大杯子中最小的那个的体积要大的时候,说明男生喝的水的水量最大就是该大杯子的体积

代码

#include<iostream>#include<algorithm>#include<cstdio>using namespace std;long long cup[200005];int main(){    int n,w;    while(~scanf("%d%d",&n,&w))    {        for(int i=0;i<2*n;i++)            scanf("%d",&cup[i]);        sort(cup,cup+2*n);        if(cup[n]>=cup[0]*2)        {            long long ans=cup[0]*n*3;  //这里要用 long long存一下,不然就wa了            if(ans>=w)                printf("%d\n",w);            else                printf("%lld\n",ans);        }        else        {            double temp=cup[n]/2.0;            double tempp=temp*n*3.0;            if(tempp>=w)                printf("%d\n",w);            else                printf("%.7llf\n",tempp);        }    }    return 0;}