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 ...
随机推荐
- Linux_Bash脚本基础
目录 目录 Bash使用基础 if 语句 运算符 逻辑表达式 不将执行指令的结果显示出来 echo 语句 从Bash接受输入参数 Case语句 循环 for 语句 While语句 内置变量和函数 AW ...
- JS对象—字符串总结(创建、属性、方法)
1.创建字符串 1.1 new String(s) String和new一起使用,创建的是一个字符串对象,存放的是字符串s的表示. 1.2 String(s) ...
- 个人珍藏的PC和安卓应用列表
个人珍藏的PC和安卓应用列表 PC应用名称 功能描述 注意事项 存储位置 维棠FLV视频下载软件 可用来下载腾讯视频的视频 将视频列表的网址粘贴到维棠软件左侧"下载"的地址中即可批 ...
- 企业SRC整理
0.SRCs|安全应急响应中心 - 0xsafe 1.腾讯安全应急响应中心(TSRC) 2.360安全应急响应中心 3.京东安全应急响应中心(JSRC) 4.平安集团安全应急响应中心(PSRC) 5. ...
- Win10.资料
1.Win10版本consumer editions和business editions有什么区别?(http://www.winwin7.com/JC/10722.html) 2.密钥 win10 ...
- linux操作系统的调度策略
linux的进程分为两种 1.实时进程,优先级高,操作系统会优先执行这种进程 2.普通进程,大多数的进程都是这种进程 调度策略 unsigned int policy; 调度策略的定义 #define ...
- Python判断端口连通性
#!/usr/bin/env python # -*- coding: utf-8 -*- import socket,sys def MySQL_Connet(MySQL_ip): MySQL_so ...
- HTML5--sessionStorage、localStorage、manifest
sessionStroage: <!DOCTYPE html> <html lang="en"> <head> <meta charset ...
- mybatis输出映射总结
使用resultType作为输出映射 只有查询出来的列名和pojo中的属性名一致时,才会映射成功, 如果不一致,可以使用resultMap最为输出类型 不管是输出单个对象还是列表(list中包括poj ...
- ExcelVBA 操作putty
Private Sub login(ip As String, userName As String, password As String) Dim TaskID As Long '设置进程id p ...