zoukankan      html  css  js  c++  java
  • CodeForces

    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.

    Examples
    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...

    题目大意:有n个男生和n个女生喝水(不超过w),杯子的型号都告诉了,男生喝的水数量都一样,女生也都一样且为男生的一半。问最多需要多少水。

    解题思路:杯子排序。选  男生最小的杯子的体积除2  和  女生最小的杯子的体积  中较小的一个作为一个标准,乘3n就是总数,再与W比较即可。唯一不清楚的地方就是输出格式,后来试了一下8位小数就过了。。

    #include<cstdio>
    #include<algorithm>
    using namespace std;
    const int maxn=2e5+10;
    int a[maxn];
    int n,w;
    
    int main()
    {
        scanf("%d %d",&n,&w);
        int m=2*n;
        for(int i=0;i<m;i++)
        {
            scanf("%d",&a[i]);
        }
        sort(a,a+m);
        double ans = min((double)a[0],(double)a[n]/2.0);
        ans = ans*n*3;
        if(ans>w)
            ans = w;
        printf("%.8f
    ",ans);
    }
  • 相关阅读:
    在Linux下运行YY,WINE方式,主要注册表修改点及字体文件列表
    安卓so下,cmake编译系统,如何仅导出指定符号
    AutoHotKey脚本模板:初始化、配置、退出
    资源ID管理插件:VS6/VS.NET
    ListView控件,表格模式下,如何调整行高
    通过wscript运行的JS脚本,如何引入另一个JS文件
    64位编译器下,将指针转换成UINT32,不需要修改编译选项的编码方式
    视频帧双缓冲区的两个版本
    opencv、numpy中矩阵转置,矩阵内的固定位置相应的坐标变换
    CMake下,某些选项的后调整
  • 原文地址:https://www.cnblogs.com/WWkkk/p/7418194.html
Copyright © 2011-2022 走看看