zoukankan      html  css  js  c++  java
  • 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 ≤ 1051 ≤ 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 ≤ 1091 ≤ 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<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
    ",min((double)w,ans*3*(double)n) );
    	
    	
    	return 0;
    }
    





  • 相关阅读:
    Linux之ARP——种种
    Linux之内核参数——backlog/somaxconn
    CLOSE_WAIT、CLOSE_WAIT原因,危害,如何避免
    OVS——大杂烩
    Linux 网络栈——
    OpenShift——大杂烩
    协议之ICMP——种种
    Neutron 理解 (8): Neutron 是如何实现虚机防火墙的 [How Neutron Implements Security Group]
    Neutron 理解 (6): Neutron 是怎么实现虚拟三层网络的 [How Neutron implements virtual L3 network]
    CIDR地址块及其子网划分(内含原始IP地址分类及其子网划分的介绍)
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/6705550.html
Copyright © 2011-2022 走看看