• 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下CPU利用率和CPU负载【转】
    Linux用户抢占和内核抢占详解(概念, 实现和触发时机)--Linux进程的管理与调度(二十)【转】
    内核中断,异常,抢占总结篇【转】
    内核中dump_stack()的实现,并在用户态模拟dump_stack()【转】
    嵌入式系统C编程之堆栈回溯【转】
    嵌入式系统C编程之错误处理【转】
    在代码中获取调用者函数的名字【转】
    手动跟踪函数的调用过程【转】
    用户态使用 glibc/backtrace 追踪函数调用堆栈定位段错误【转】
    Linux运行时I/O设备的电源管理框架【转】
  • 原文地址:https://www.cnblogs.com/WWkkk/p/7418194.html
Copyright © 2020-2023  润新知