【23.33%】【codeforces 557B】Pasha and Tea
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的更多相关文章
- 【23.33%】【codeforces 664C】International Olympiad
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【23.33%】【hdu 5945】Fxx and game
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Submission(s ...
- 【CodeForces 557B】Pasha and Tea
题 题意 总共有 w 克蛋糕,2n 个盘子,第 i 个盘子容量为 ai ,n 个女孩和 n 个男孩,男孩得到的是女孩得到的蛋糕的两倍,求他们得到蛋糕的最大值. 分析 把盘子从小到大排序,然后 女生得到 ...
- 【 BowWow and the Timetable CodeForces - 1204A 】【思维】
题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...
- 【23. 合并K个排序链表】【困难】【优先队列/堆排序】
合并 k 个排序链表,返回合并后的排序链表.请分析和描述算法的复杂度. 示例: 输入: [ 1->4->5, 1->3->4, 2->6] 输出: 1->1-> ...
- 【20.23%】【codeforces 740A】Alyona and copybooks
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【23.39%】【codeforces 558C】Amr and Chemistry
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【33.10%】【codeforces 604C】Alternative Thinking
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【25.33%】【codeforces 552D】Vanya and Triangles
time limit per test4 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...
随机推荐
- HTTP (httpwebrequest)
1.GET请求: public static string Get(string url) { string buffer = ""; try { HttpWebRequest r ...
- 在Google Drive上建立免费静态站点
现今建立一个属于自己的站点已经是一件非常普遍和简单的事情了. 你能够选择买空间,买域名.你也能够使用免费空间.免费域名.你能够选择动态的php wordpress,joomla或者是静态的站点(如使用 ...
- js38---门面模式
(function(){ //门面 function addEvebtFacade(el,type,fn){ if(window.addEventListener){ //使用与火狐浏览器 alert ...
- 27.mutex跨进程通信
创建互斥量mutex HANDLE mutex = CreateMutexA(NULL, TRUE, name); 根据id打开mutex HANDLE mutex = OpenMutexA(MUTE ...
- SQL创建数据库、表、存储过程及调用
--如果存在数据库PRogrammerPay 就删除 if exists (select * from sysdatabases where name='programmerPay') drop d ...
- Docker+SVN
原文:Docker+SVN mkdir /cnex/svndocker pull garethflowers/svn-server docker run -d --name svn-server - ...
- asp.net Code学习一(vs code跨平台软件操作)
1.命令行: dotnet new -t web 创建web项目 dotnet new restore build pubilsh run test pack dotnet -info / -h do ...
- git 当出现 devirge 时,一个是commit的提交顺序不对
进入新分支1.git pull origin branchname 2.修改 3.git add . 4.git commit 5. git pull 6.git push 出现分歧要,就版本回退, ...
- Python 极简教程(五)输入输出
输入函数,用于接收键盘输入.主要用于在学习和练习过程中,增加练习的乐趣.让我们的程序相对完整和具备简单的交互能力. 输出函数,将代码运行结果打印在控制台上,同样也能让我们观察程序运行的结果.也是为了增 ...
- Docker---(2)为什么要用Docker
原文:Docker---(2)为什么要用Docker 版权声明:欢迎转载,请标明出处,如有问题,欢迎指正!谢谢!微信:w1186355422 https://blog.csdn.net/weixin_ ...