【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 ...
随机推荐
- cron 简单任务调度 go
package main import ( "github.com/robfig/cron" "log" ) func main() { i := 0 c := ...
- Ubuntu 美团sql优化工具SQLAdvisor的安装(转)
by2009 by2009 发表于 3 个月前 SQLAdvisor简介 SQLAdvisor是由美团点评公司技术工程部DBA团队(北京)开发维护的一个分析SQL给出索引优化建议的工具.它基于MySQ ...
- [ReasonML] Named & optional params
// ::country is named param // ::country=?: which make it optional // because we make ::country=? op ...
- 15.Node.js REPL(交互式解释器)
转自:http://www.runoob.com/nodejs/nodejs-tutorial.html Node.js REPL(Read Eval Print Loop:交互式解释器) 表示一个电 ...
- Code froces 831 A. Unimodal Array
A. Unimodal Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- BZOJ2806: [Ctsc2012]Cheat(广义后缀自动机,单调队列优化Dp)
Description Input 第一行两个整数N,M表示待检查的作文数量,和小强的标准作文库的行数接下来M行的01串,表示标准作文库接下来N行的01串,表示N篇作文 Output N行,每行一个整 ...
- yarn的安装和使用
yarn的简介: Yarn是facebook发布的一款取代npm的包管理工具. yarn的特点: 速度超快. Yarn 缓存了每个下载过的包,所以再次使用时无需重复下载. 同时利用并行下载以最大化资源 ...
- vim学习3
可视模式:
- 第一个使用Spring Tool Suite(STS)和Maven建立的Spring mvc 项目
一.目标 在这篇文章中.我将要向您展示怎样使用Spring Frameworks 和 Maven build创建您的第一个J2ee 应用程序. 二.信息 Maven是一个java项目的构建工具(或者自 ...
- 12. ZooKeeper之Java客户端API使用—创建会话。
转自:https://blog.csdn.net/en_joker/article/details/78686649 客户端可以通过创建一个ZooKeeper(org.apache.zookeeper ...