Codeforces 557B Pasha and Tea pour

Source: Internet
Author: User

Test instructions: Pasha has 2n cups, each cup has a different volume. Pasha has 2n friends, men and women each n. Now pasha to the total volume W of tea poured in 2n cups, to the 2n friends, and the same sex Friends Cup tea volume is the same, and each male friend Cup tea volume is each female friends cup of tea twice times the volume. The maximum value of the sum of the tea volume in all friends ' cups.





water problem. First, according to the volume of the Cup, the smaller of the N Cup must be given to the girls, the larger n cups to the boys. If not, if a male friend Cup volume than a female friend Cup volume is small, because the male Friends cup tea volume is larger, then exchange their cups, can still be able to load their original tea. So it seems that this sort of method can be. So since each same-sex friend's tea as much, we only need to consider the male friends of the cup volume is the smallest and female friends of the smallest cup volume can be. Female friends with the smallest cup volume of x, male Friends Total cup volume is the smallest of Y, because the total amount of tea only W, so the final answer is min (min (2x,y) *1.5*n,w).






#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <string > #include <algorithm> #include <stack> #include <queue> #include <vector> #include <map > #include <set>using namespace std;const int MAX = 100005;int n;double W, a[2*max];void input () {for    (int i = 0; i < 2*n; i++)        scanf ("%lf", &a[i]);} void Solve () {    sort (A, a + 2*n);    printf ("%.6lf\n", Min (min (2*a[0], a[n]) *1.5*n, W));} int main () {while    (scanf ("%d%lf", &n, &w)! = EOF)    {        input ();        Solve ();    }    return 0;}




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Codeforces 557B Pasha and Tea pour

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.