Pasha and Tea
Pasha and Tea
1 second
256 megabytes
standard input
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.
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.
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.
2 4
1 1 1 1
3
3 18
4 4 4 2 2 2
18
1 5
2 3
4.5
Pasha also has candies that he is going to give to girls but that is another task...
最多可以用多少水,看是女生用的多还是男生可以用的多,毕竟还有二倍限制
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <limits>
#include <queue>
#include <stack>
#include <vector>
#include <map> using namespace std; #define N 200005
#define INF 0xfffffff
#define PI acos (-1.0)
#define EPS 1e-8
#define Lson rt<<1, l, tree[rt].mid ()
#define Rson rt<<1|1, tree[rt].mid () + 1, r int main ()
{
int n;
double w, a[N]; while (~scanf ("%d%lf", &n, &w))
{
for (int i=; i<*n; i++)
scanf ("%lf", &a[i]); sort (a, a+*n); double ans = min (a[], a[n]/);
ans = ans * * n;
ans = min (w*1.0, ans); printf ("%.7f\n", ans);
}
return ;
}
也可以二分,因为你二分学的好(话说,二分是什么
http://blog.csdn.net/u014427196
Pasha and Tea的更多相关文章
- 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 ...
- Codeforces Round #311 (Div. 2)B. Pasha and Tea二分
B. Pasha and Tea time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- 【23.33%】【codeforces 557B】Pasha and Tea
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- codeforces 557B. Pasha and Tea 解题报告
题目链接:http://codeforces.com/problemset/problem/557/B 题目意思:有 2n 个茶杯,规定第 i 个茶杯最多只能装 ai 毫升的水.现在给出 w 毫升的水 ...
- 【CodeForces 557B】Pasha and Tea
题 题意 总共有 w 克蛋糕,2n 个盘子,第 i 个盘子容量为 ai ,n 个女孩和 n 个男孩,男孩得到的是女孩得到的蛋糕的两倍,求他们得到蛋糕的最大值. 分析 把盘子从小到大排序,然后 女生得到 ...
- CF 557B(Pasha and Tea-贪心)
B. Pasha and Tea time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #311 (Div. 2)
我仅仅想说还好我没有放弃,还好我坚持下来了. 最终变成蓝名了,或许这对非常多人来说并不算什么.可是对于一个打了这么多场才好不easy加分的人来说,我真的有点激动. 心脏的难受或许有点是由于晚上做题时太 ...
- Codeforces Round #311 (Div. 2) A,B,C,D,E
A. Ilya and Diplomas 思路:水题了, 随随便便枚举一下,分情况讨论一下就OK了. code: #include <stdio.h> #include <stdli ...
- Codeforces Round #311 (Div. 2)题解
A. Ilya and Diplomas time limit per test 1 second memory limit per test 256 megabytes input standard ...
随机推荐
- Window 相关命令
net user Administrator /Active:Yes NET USER 用于创建和修改计算机上的用户帐户.当不带选项使用本命令时,它会列出计算机上的用户帐户.用户帐户的信息存储在用户帐 ...
- jmeter之非GUI启动与执行脚本
启动jmeter的图形界面可以从dos窗口输命令启动:图形界面还是比较占资源的,这时候可以通过dos窗口来执行脚本,获取性能结果 目录 1.dos窗口启动jmeter图形界面 2.dos窗口执行脚本, ...
- Vagrant 手册之同步目录 - 基本用法
原文地址 - 概述 原文地址 - 基本用法 同步目录 Synced folder 支持在宿主机和客户机之间共享目录,从而允许你在宿主机的项目文件上工作,但是可以在客户机上编译并运行. 默认情况下,Va ...
- pandas dataframe 一行变多行 (query pv统计term pv)
关键字: 用jieba切词 用expand 一列变多列 用stack 列转行 用group by + aggr 相同term的pv求和 上效果: query pv 今日新鲜事 今日头条 北京天气 上海 ...
- EasyUI的时间控件禁止输入
<td class="right">制单日期:</td> <td class="left"> <input name ...
- Python 根据入栈顺利判定出栈顺序
1.读取入栈,出栈数据: 2.把数据分别转化成整数列表: 3.新建栈列表,用入栈数据进行压栈:如果栈列表不为空,并且栈顶层数据为出栈的元素:删除栈列表的顶层数据: 4.如果栈列表不为空,说明栈列表里面 ...
- Junit测试错误:### Error building SqlSession
错误代码: org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession.### The error ...
- 清除mac中自动记录的git用户名和密码
应用程序-实用工具-双击钥匙串-右上角搜索github-右击选项删除
- Codeforces - 1194D - 1-2-K Game - dp
https://codeforc.es/contest/1194/problem/D 打个n=30的表好像看出了规律. 其实假设k==3,那么 sg[0]=0, sg[1]=mex{sg[0]}=1, ...
- python学习三十四天函数高阶函数定义及用法
python函数高阶函数是把函数当成一个变量,传递给函数作为参数,或者函数的返回值里面有函数,都称为高阶函数, 1,把函数作为参数传递 def dac(x,y): return x+y def tes ...