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.

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的一壶水  n个男生 n个女生 男生喝的水一样 女生喝的水一样 并且 男生喝的水是女生喝的水的二倍

2*n个杯子 容积为a1,a2,a...a2*n

思路: 将2*n个杯子的容积排序

二分容积最小的杯子 直到满足条件

二分的姿势  弱弱的贴一个

#include<bits/stdc++.h>
using namespace std;
int n,w;
int a[200005];
int main()
{
scanf("%d%d",&n,&w);
for(int i=0;i<2*n;i++)
scanf("%d",&a[i]);
sort(a,a+2*n);
double mi=(double)a[0],ma=(double)a[n];
double exm=(double)w/(3*n);
// cout<<mi<<" "<<ma<<" "<<exm<<endl;
if(exm<=mi&&exm*2<=ma)
{
printf("%d",w);
return 0;
}
double l=0.0;
double r=mi,mid;
while(r-l>0.000001)
{
mid=(l+r)/2;
// cout<<mid<<endl;
if(mid*2>ma||mid*3*n>w)
r=mid;
else
l=mid;
}
printf("%lf\n",l*3*n);
return 0;
}

  

Codeforces Round #311 (Div. 2)B. Pasha and Tea二分的更多相关文章

  1. Codeforces Round #311 (Div. 2)B. Pasha and Tea 水题

    B. Pasha and Tea Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/557/prob ...

  2. Codeforces Round #297 (Div. 2)B. Pasha and String 前缀和

    Codeforces Round #297 (Div. 2)B. Pasha and String Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx ...

  3. 字符串处理 Codeforces Round #297 (Div. 2) B. Pasha and String

    题目传送门 /* 题意:给出m个位置,每次把[p,len-p+1]内的字符子串反转,输出最后的结果 字符串处理:朴素的方法超时,想到结果要么是反转要么没有反转,所以记录 每个转换的次数,把每次要反转的 ...

  4. Codeforces Round #365 (Div. 2) C - Chris and Road 二分找切点

    // Codeforces Round #365 (Div. 2) // C - Chris and Road 二分找切点 // 题意:给你一个凸边行,凸边行有个初始的速度往左走,人有最大速度,可以停 ...

  5. Codeforces Round #311 (Div. 2)

    我仅仅想说还好我没有放弃,还好我坚持下来了. 最终变成蓝名了,或许这对非常多人来说并不算什么.可是对于一个打了这么多场才好不easy加分的人来说,我真的有点激动. 心脏的难受或许有点是由于晚上做题时太 ...

  6. Codeforces Round #311 (Div. 2) A,B,C,D,E

    A. Ilya and Diplomas 思路:水题了, 随随便便枚举一下,分情况讨论一下就OK了. code: #include <stdio.h> #include <stdli ...

  7. Codeforces Round #311 (Div. 2)题解

    A. Ilya and Diplomas time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. Codeforces Round #337 (Div. 2) A. Pasha and Stick 数学

    A. Pasha and Stick 题目连接: http://www.codeforces.com/contest/610/problem/A Description Pasha has a woo ...

  9. Codeforces Round #330 (Div. 2) B. Pasha and Phone 容斥定理

    B. Pasha and Phone Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/pr ...

随机推荐

  1. Grid 网格布局

    CSS 网格布局(Grid Layout) 是CSS中最强大的布局系统. 这是一个二维系统,这意味着它可以同时处理列和行,不像 flexbox 那样主要是一维系统. 你可以通过将CSS规则应用于父元素 ...

  2. 两种缓存淘汰算法LFU&LRU

    LRU全称是Least Recently Used,即最近最久未使用的意思. LRU算法的设计原则是:如果一个数据在最近一段时间没有被访问到,那么在将来它被访问的可能性也很小.也就是说,当限定的空间已 ...

  3. LeetCode 138——复制带随机指针的链表

    1. 题目 2. 解答 第一次遍历链表的时候,复制旧链表的节点值建立一个新的链表,同时定义一个 unordered_map 作为哈希表,哈希表的键为旧链表的节点指针,值为新链表的节点指针. 然后,第二 ...

  4. LeetCode - 231. Power of Two - 判断一个数是否2的n次幂 - 位运算应用实例 - ( C++ )

    1.题目:原题链接 Given an integer, write a function to determine if it is a power of two. 给定一个整数,判断该整数是否是2的 ...

  5. [C++] Copy Control (part 1)

    Copy, Assign, and Destroy When we define a class, we specify what happens when objects of the class ...

  6. Python3 深浅拷贝

    一 定义 在Python中对象的赋值其实就是对象的引用.当创建一个对象,把它赋值给另一个变量的时候,python并没有拷贝这个对象,只是拷贝了这个对象的引用而已. 浅拷贝: 浅拷贝值只拷贝一层,具有自 ...

  7. The Uncle_b's First Love

    Description ACM成立大会之后,uncle_b被其中一个大一女孩深深地吸引,但腼腆的B叔又不知道如何去表达自己内心的想法,经calmound神的指导,B叔决定写封情书给对方.他从Tamar ...

  8. II 3.1 连接到服务器

    II 3.1 连接到服务器 package socket; import java.io.IOException; import java.io.InputStream; import java.ne ...

  9. lintcode-156-合并区间

    156-合并区间 给出若干闭合区间,合并所有重叠的部分. 样例 给出的区间列表 => 合并后的区间列表: [ [ [1, 3], [1, 6], [2, 6], => [8, 10], [ ...

  10. python获取本地时间

    python本地时间 import time # 格式化成2016-03-20 11:45:39形式 now = time.strftime("%Y-%m-%d %H:%M:%S" ...