程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> CF 557B(Pasha and Tea-貪心)

CF 557B(Pasha and Tea-貪心)

編輯:C++入門知識

CF 557B(Pasha and Tea-貪心)


 

B. Pasha and Tea time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of w milliliters and 2n tea cups, each 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 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 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;
    }
    


     

     

     

     

     

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved