0
点赞
收藏
分享

微信扫一扫

Codeforces Round #311 (Div. 2) B. Pasha and Tea【二分】

独西楼Q 2023-03-04 阅读 58




B. Pasha and Tea



time limit per test



memory limit per test



input



output


w milliliters and 2n tea cups, each cup is for one of Pasha's friends. The i-th cup can hold at most ai

n boys and exactly n

  • w
  • Pasha pours the same amount of water to each girl;
  • Pasha pours the same amount of water to each boy;
  • x milliliters of water, then each boy gets 2x

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



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.

ai (1 ≤ ai ≤ 109, 1 ≤ i ≤ 2n) — the capacities of Pasha's tea cups in milliliters.


Output



10 - 6.


Sample test(s)



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

二分答案即可


#include <stdio.h>
#include <ctime>
#include <math.h>
#include <limits.h>
#include <complex>
#include <string>
#include <functional>
#include <iterator>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <bitset>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <iostream>
#include <ctime>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <time.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>

using namespace std;

int n, w;
double p[200010];

int main()

{
while (cin >> n)
{
cin >> w;
for (int i = 1; i <= n * 2; i++)
scanf("%lf",&p[i]);
sort(p + 1, p + 1 + 2 * n);
int t1 = p[1];
int t2 = p[n + 1];
double ans;

if (t2 >= t1 * 2) //yes
{
double left = 0;
double right = w;
double mid;
while (left + 0.000000001 <right)
{
mid = (left + right) / 2;
//n*X + n*X/2 <= mid
double x = mid / n / 3;
if (x <= t1)
{
left = mid;
ans = mid;
}
else
right = mid;
}
}
else
{
double left = 0;
double right = w;
double mid;
while (left + 0.000000001 <right)
{
mid = (left + right) / 2;
//n*X + n*X/2 <= mid
double x = mid * 2 / n / 3;
if (x <= t2)
{
left = mid;
ans = mid;
}
else
right = mid;
}
}
printf("%.8lf\n",ans);
}
return 0;
}



举报

相关推荐

0 条评论