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);
    }
  • 相关阅读:
    ubuntu正确输入用户名密码后重复登录界面
    Spring第一个程序
    winrar解压spring出现“路径和文件名总长度必须不能超过 260 个字符!”错误的解决方法
    Spring属性装配之属性类型是另外一个被装载的类
    classpath、path、JAVA_HOME的作用及JAVA环境变量配置
    ubuntu基本命令篇15系统管理time命令中Real,User,Sys概念
    基于linux使用mysql二进制包安装mysql5.5
    shell循环语法
    db笔记本
    shell function
  • 原文地址:https://www.cnblogs.com/WWkkk/p/7418194.html
Copyright © 2011-2022 走看看