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. TW实习日记:第19天

    今天一早上改完信息门户的代码之后,发现接口又出了问题,查了半天都不知道,原来又是网端的问题...真是心累啊,调整了一些细节样式,以及终于把企业微信的消息推送功能做完了.关键就在于有个表存放微信id的字 ...

  2. Memcache的客户端连接系列(二) Python

    关键词: Memcached   Python 客户端 声明:本文并非原创,转自华为云帮助中心的分布式缓存服务(Memcached)的用户指南.客户端连接方法通用,故摘抄过来分享给大家. Python ...

  3. Skype for Business Server 方案

    方案说明: 高可用性的配置屏蔽了单点故障,使得当一个服务器节点失效时,另外的可用的节点能够进行服务的接管.可伸缩性的配置可以保证当即时沟通平台的使用用户增加时,该平台应该具有良好的可伸缩性,能非常方便 ...

  4. C#二次封装虹软arc研究

    相信很多用C#又想用虹软的SDK的童鞋要花很多心思去研究怎么转换,所以写了一篇文章和一个demo方便用C#的童鞋方便调用虹软的接口, 文章的地址是:https://blog.xgcos.com/sho ...

  5. POJ 1655 Balancing Act(求树的重心)

    Description Consider a tree T with N (1 <= N <= 20,000) nodes numbered 1...N. Deleting any nod ...

  6. vue移动音乐app开发学习(二):页面骨架的开发

    本系列文章是为了记录学习中的知识点,便于后期自己观看.如果有需要的同学请登录慕课网,找到Vue 2.0 高级实战-开发移动端音乐WebApp进行观看,传送门. 完成后的页面状态以及项目结构如下: 一: ...

  7. 硬件原理图Checklist检查表(通用版)

    类别 描述 检视规则 原理图需要进行检视,提交集体检视是需要完成自检,确保没有低级问题. 检视规则 原理图要和公司团队和可以邀请的专家一起进行检视. 检视规则 第一次原理图发出进行集体检视后所有的修改 ...

  8. Mishka and Contest(模拟水题)

    Mishka started participating in a programming contest. There are nn problems in the contest. Mishka' ...

  9. OSG数学基础:坐标系变换

    三维实体对象需要经过一系列的坐标变换才能正确.真实地显示在屏幕上.在一个场景中,当读者对场景中的物体进行各种变换及相关操作时,坐标系变换是非常频繁的. 坐标系变换通常包括:世界坐标系-物体坐标系变换. ...

  10. 关于FEer发展方向的思考

    今天学习了HTTP权威指南这本书,虽然标题是对FEer发展的思考,不过我打算稍后再说这个议题,先对今天学习的内容做个总结. 首先:原来访问服务器的方式有多重,核心是URI,也就是统一资源定位,按照访问 ...