time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard 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…

【题目链接】:http://codeforces.com/contest/557/problem/B

【题解】



如果总的茶的体积tt确定了;

设每个女孩的杯子中水的体积为x

则x*n+2*x*n=tt

则x=tt/(3*n;

则二分tt可以快速获取x,判断大于等于x的杯子个数是不是2*n,大于等于2*x的杯子个数是不是n;

是的话就增大茶体积否则减小;



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x)
#define pri(x) printf("%d",x)
#define prl(x) printf("%I64d",x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int MAXN = 2e5+100;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0); int n,tw;
int a[MAXN];
double w; bool ok(double tt)
{
double tn = n;
double x = tt/(tn*(3.0));
int n1 = 0,n2 = 0;
rep1(i,1,2*n)
if (a[i]>=x)
n1++;
if (n1<2*n) return false;
double tempx = x*2;
rep1(i,1,2*n)
if (a[i]>=tempx)
n2++;
if (n2<n) return false;
return true;
} int main()
{
//freopen("F:\\rush.txt","r",stdin);
rei(n);rei(tw);
w = tw;
rep1(i,1,2*n)
rei(a[i]);
double l = 0,r = w,ans1=0;
while (abs(r-l)>=1e-6)
{
double m = (l+r)/2.0;
if (ok(m))
{
l = m;
ans1 = m;
}
else
r = m;
}
printf("%.6lf\n",ans1);
return 0;
}

【23.33%】【codeforces 557B】Pasha and Tea的更多相关文章

  1. 【23.33%】【codeforces 664C】International Olympiad

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  2. 【23.33%】【hdu 5945】Fxx and game

    Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Submission(s ...

  3. 【CodeForces 557B】Pasha and Tea

    题 题意 总共有 w 克蛋糕,2n 个盘子,第 i 个盘子容量为 ai ,n 个女孩和 n 个男孩,男孩得到的是女孩得到的蛋糕的两倍,求他们得到蛋糕的最大值. 分析 把盘子从小到大排序,然后 女生得到 ...

  4. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  5. 【23. 合并K个排序链表】【困难】【优先队列/堆排序】

    合并 k 个排序链表,返回合并后的排序链表.请分析和描述算法的复杂度. 示例: 输入: [ 1->4->5, 1->3->4, 2->6] 输出: 1->1-> ...

  6. 【20.23%】【codeforces 740A】Alyona and copybooks

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. 【23.39%】【codeforces 558C】Amr and Chemistry

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. 【33.10%】【codeforces 604C】Alternative Thinking

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 【25.33%】【codeforces 552D】Vanya and Triangles

    time limit per test4 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...

随机推荐

  1. JavaScript学习总结(10)——实用JS代码大全

    事件源对象  event.srcElement.tagName  event.srcElement.type 捕获释放  event.srcElement.setCapture();   event. ...

  2. 设计模式之禅——模板方法模式&钩子方法

    ** **板方法模式的定义: 定义一个操作的算法的框架,而将一些步骤延迟到子类中.使得子类可以不改变一个算法的框架即可重定义该算法的某些特定步骤. 例子:做一个简单的悍马车的模型 见UML图 一个抽象 ...

  3. bootstrap之Orientation

    Orientation 调整屏幕方向的操作. package io.appium.android.bootstrap.handler; import android.os.RemoteExceptio ...

  4. linux下uboot kernel操作cpu寄存器

    大多数的内核里面都有会对GPIO的操作,而且内核里面对GPIO进行配置也很方便,要什么功能就配置成什么就可以了. 还有一些寄存器是内核没有配置到的,但是我们要操作怎么办,内核里面也定义了相关的接口函数 ...

  5. mahout用到的典型测试数据集

    http://archive.ics.uci.edu/ml/databases/synthetic_control/ 继续

  6. Fedora 10下应用网络模拟器NS心得

    650) this.width=650;" onclick='window.open("http://blog.51cto.com/viewpic.php?refimg=" ...

  7. 使用Multiplayer Networking做一个简单的多人游戏例子-1/2(换一种方法)

    SynMove.cs using UnityEngine; using System.Collections; using UnityEngine.Networking; public class S ...

  8.  洛谷 P3056 [USACO12NOV]笨牛Clumsy Cows

    P3056 [USACO12NOV]笨牛Clumsy Cows 题目描述 Bessie the cow is trying to type a balanced string of parenthes ...

  9. 用VBS控制鼠标,在Excel2010、2013,64位中

    原作者文章地址:http://demon.tw/programming/vbs-control-mouse.html 感谢原作者的攻略.才使我学会用VBS控制鼠标. 但是问题接踵而至,Excel200 ...

  10. KNIMI数据挖掘建模与分析系列_002_利用KNIMI做商超零售关联推荐

    利用KNIMI做商超零售关联推荐 http://blog.csdn.net/shuaihj 一.測试数据 须要測试数据,请留下邮箱 二.训练关联推荐规则 1.读取销售记录(sales.table) 2 ...