zoukankan      html  css  js  c++  java
  • Pasha and Tea

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

    最多可以用多少水,看是女生用的多还是男生可以用的多,毕竟还有二倍限制

     1 #include <iostream>
     2 #include <cstring>
     3 #include <cstdio>
     4 #include <algorithm>
     5 #include <cmath>
     6 #include <cstdlib>
     7 #include <limits>
     8 #include <queue>
     9 #include <stack>
    10 #include <vector>
    11 #include <map>
    12 
    13 using namespace std;
    14 
    15 #define N 200005
    16 #define INF 0xfffffff
    17 #define PI acos (-1.0)
    18 #define EPS 1e-8
    19 #define Lson rt<<1, l, tree[rt].mid ()
    20 #define Rson rt<<1|1, tree[rt].mid () + 1, r
    21 
    22 int main ()
    23 {
    24     int n;
    25     double w, a[N];
    26 
    27     while (~scanf ("%d%lf", &n, &w))
    28     {
    29         for (int i=0; i<2*n; i++)
    30             scanf ("%lf", &a[i]);
    31 
    32         sort (a, a+2*n);
    33 
    34         double ans = min (a[0], a[n]/2);
    35         ans = ans * 3 * n;
    36         ans = min (w*1.0, ans);
    37 
    38         printf ("%.7f
    ", ans);
    39     }
    40     return 0;
    41 }

    也可以二分,因为你二分学的好(话说,二分是什么

    http://blog.csdn.net/u014427196

    让未来到来 让过去过去
  • 相关阅读:
    anything vs everything
    cong
    invalid initialization of non-const reference of type与discards qualifiers
    gvew
    3.2存储器层次结构 -- 《深入理解计算机系统》☆☆☆☆☆
    2.2优化编译器的能力和局限性
    2.1.2优化程序性能
    2.1.1优化程序性能
    linux中获取堆栈空间大小的方法
    优美的英文诗歌Beautiful English Poetry
  • 原文地址:https://www.cnblogs.com/Tinamei/p/4708187.html
Copyright © 2011-2022 走看看