B. Pasha and Tea
来源:互联网 发布:如果黄家驹还活着知乎 编辑:程序博客网 时间:2024/05/22 19:00
Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of wmilliliters 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 exceed10 - 6.
2 41 1 1 1
3
3 184 4 4 2 2 2
18
1 52 3
4.5
Pasha also has candies that he is going to give to girls but that is another task.
解题说明:此题是一道模拟题,为了保证尽可能倒更多的水,可以采用贪心方法。
#include<stdio.h>#include <string.h>#include<iostream>#include<algorithm>using namespace std;int main(){long long i,n,w;long double r;cin>>n>>w;long a[2*n];for(i=0;i<2*n;i++){cin>>a[i];}sort(a,a+2*n);printf("%.9f",min(min(3.0*a[0],1.5*a[n])*n,1.0*w));return 0;}
- B. Pasha and Tea
- cf#311 B. Pasha and Tea
- CF 557B(Pasha and Tea-贪心)
- codeforces B. Pasha and Tea二分
- CodeForces#311 B. Pasha and Tea
- codeforces 557B Pasha and Tea-水题
- CF 557B Pasha and Tea
- CodeForces 557B Pasha and Tea
- Codeforces 557B Pasha and Tea 【数学】
- CodeForces 557B-Pasha and Tea【模拟】
- CodeForces 557B Pasha and Tea
- 【23.33%】【codeforces 557B】Pasha and Tea
- codeforce Pasha and Tea
- codeforces #311 B B. Pasha and Tea(贪心)
- Codeforces 557B Pasha and Tea 倒茶
- Codeforces Round #311 (Div. 2) B. Pasha and Tea
- Codeforces Round #311 (Div. 2) B. Pasha and Tea
- Code Forces 557 B. Pasha and Tea(水~)
- LeetCode--subsets问题
- 定时同步sql server数据到mysql
- Linux初入门
- mysqlmb4
- Java用邻接矩阵实现广度优先
- B. Pasha and Tea
- leetcode: (125) Valid Palindrome
- EditText设置/隐藏光标位置、选中文本和获取/清除焦点
- Android使用ListView divider属性设置分界线,显示不出来的问题
- sql server中高并发情况下 同时执行select和update语句死锁问题
- 地图打印资源 ArcEngine
- ViewController之间的block传值
- html 添加视频
- axis webservice调试