CodeForces - 557B Pasha and Tea (贪心)

zed(Rust)开源项目完整源码 「zed(Rust)开源项目完整源码」是开源项目(Rust)。项目简介:Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.源码完整,下载解压即可查看使用,适合学习参考、课程设计与二次开发。 立即下载

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.

Example
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

题目大意就是给2n个杯子,w体积的水,每个杯子都有它的体积,女生男生各n人,一人一个杯子,所有女生喝的水量相同,所有男生喝的水量相同,女生喝的水是男生的一半,问w体积的水倒给这些杯子,最多可以用掉多少体积的水

显然就是将杯子的体积都排序,大杯子给男生,小杯子给女生,然后计算男生或女生喝的水的水量

当小杯子中最小的那个的体积的  两倍  比大杯子中最小的那个的体积要小的时候,说明女生喝的水的水量最大就是该小杯子的体积

当小杯子中最小的那个的体积的  两倍  比大杯子中最小的那个的体积要大的时候,说明男生喝的水的水量最大就是该大杯子的体积

代码

#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
long long cup[200005];
int main()
{
    int n,w;
    while(~scanf("%d%d",&n,&w))
    {
        for(int i=0;i<2*n;i++)
            scanf("%d",&cup[i]);
        sort(cup,cup+2*n);
        if(cup[n]>=cup[0]*2)
        {
            long long ans=cup[0]*n*3;  //这里要用 long long存一下,不然就wa了
            if(ans>=w)
                printf("%d\n",w);
            else
                printf("%lld\n",ans);
        }
        else
        {
            double temp=cup[n]/2.0;
            double tempp=temp*n*3.0;
            if(tempp>=w)
                printf("%d\n",w);
            else
                printf("%.7llf\n",tempp);
        }
    }
    return 0;
}



IEC 63281-3-1:2024 电动运输车 - 第3-1部分:考虑实际使用温度条件的电动滑板车总运行时间性能测试方法 - 完整英文电子版(30页) IEC 63281-3-1:2024规定了电动滑板车单人运输总运行时间的测试方法,考虑了用户在不同温度下驾驶时的实际使用温度条件,用于公路或公共场所。 本文件不涵盖残障人士或老年人的电动滑板车。此外,本文件不包括货运电动滑板车。 立即下载

相关推荐

植物大战僵尸神人版-手机版-arm64-2026.10.30-手机版.apk.1

植物大战僵尸神人版-手机版-arm64-2026.10.30-手机版.apk.1

Codeforces 557B Pasha and Tea 倒茶

题意:Pasha有2n个茶杯,每个茶杯的容积不同。Pasha有2n个朋友,男女各n个。现在Pasha要将总容积为w的茶倒在2n个茶杯里,分给这2n个朋友,并规定同性别的朋友茶杯中的茶容积相同,且每个男性朋友茶杯中茶的容积是每个女性朋友茶杯中茶的容积的两倍。求所有朋友茶杯中的茶容积之和的最大值。 水题。首先按照茶杯的容积排序,较小的n个茶杯肯定是分给了女生,较大的n

FirstLucker 1893

OpenGL纹理贴图

OpenGL纹理1. 基本概念2. 纹理环绕方式3. 纹理过滤3.1 GL_NEAREST3.2 GL_LINEAR3.3 多级渐远纹理 (Mipmap)4. 纹理加载与创建4.1 纹理加载4.2 纹理创建4.3 纹理的使用 1. 基本概念 纹理是一个2D图片(甚至也有1D和3D的纹理),它可以用来表示物体的细节特征,希望绘制一个有足够多细节的物体,当然可以用足够多的顶点颜色来描述,但是无疑也增加了许多额外的开销;另一种办法就是使用纹理。 学习之前先展示一张实现的纹理图以更好理解纹理! 还是这张图为了将纹

牵LV小猪精的博客 8921

CF 557B(Pasha and Tea-贪心)

B. Pasha and Tea time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Pasha decided to invite his friends to a te

nike0good |Oier&ACMer | 熟能生巧 1722

【冷冻电镜】RELION5.0使用教程总结

对于您自己的数据,您可能希望使用各种倾斜系列对齐方法,然后比较每种方法生成的断层扫描图像的质量(参见下一步)。通过检查 CtfFind job 的 tilt_series 目录中的star文件来检查几个倾斜系列的散焦值。GitHub上也有人反应这个问题,目前我的解决方案是下载了较低版本的CTFFIND的,降级到4.1.10可以成功运行。此外,logfile.pdf 文件包含所有显微照片的有用参数图,例如散焦、像散、估计分辨率等,以及整个数据集中这些值的直方图。的目录,以及指向此目录的符号链接。

进阶中的程序员吃吃的博客 4215

从零到一:手把手教你构建工业级Modbus转MQTT网关(STM32+ESP8266实战)

本文详细介绍了如何利用STM32和ESP8266构建工业级Modbus转MQTT网关,涵盖硬件选型、代码示例、协议转换及稳定性设计。重点解析Modbus RTU与MQTT协议对接阿里云物联网平台的实战步骤,确保数据可靠传输与长期稳定运行,为工业物联网应用提供完整解决方案。

u0v1w2x3的博客 684

PyTorch 2.0 自动求导实战:3种布局下矩阵向量求导结果验证

本文通过PyTorch 2.0的自动求导功能,详细验证了矩阵向量求导在分子布局、分母布局和混合布局下的结果差异。通过线性代数基础理论和实战代码示例,帮助开发者深入理解不同布局对梯度计算的影响,提升深度学习模型实现的准确性。

weixin_34265814的博客 378

openlayers6【十九】vue HeatmapLayer热力图层实现热力图效果详解

文章目录1. 写在前面2. Heatmap 类实现热力图2.1 Heatmap 参数2.2 实现热力图3. 完整代码4. 添加删除map图层的方法5. 热力图自身的get,set方法 1. 写在前面 我们主要看热力图的效果,区域绘制效怎么设置详细内容可以访问 openlayers6【十七】vue VectorLayer矢量图层画地图省市区,多省市区(粤港澳大湾区)效果详解 在 openlayers 中,图层是使用 layer 对象表示的,主要有 WebGLPoints Layer、热度图(HeatMap L

@必意玲 1万+

Codeforces 557B Pasha and Tea【二分+思维】

Test.

mengxiang000000 623

Halcon手眼标定实战:九点标定法从入门到精通(附完整代码)

本文详细介绍了Halcon环境下九点标定法的完整实现流程,从基础概念到实战技巧,帮助开发者快速掌握手眼标定技术。通过精确采集图像坐标与机械坐标,计算仿射变换矩阵,实现相机与机械臂坐标系的精确映射,适用于工业自动化中的平面定位场景。

v4w5x6的博客 410

金融数字化——详解2025年金融智能体深度应用报告【附全文阅读】

《2025年金融智能体深度应用报告》显示,金融智能体已实现80%部署率,推动行业效率提升30%-50%。报告指出智能体通过"感知-推理-规划-执行-进化"机制突破大模型局限,在风控、客服、投研等100+场景实现自动化。典型案例显示,工商银行信贷审批效率提升60%,蚂蚁数科智能客服解决80%问题。尽管面临系统协同、标准缺失等挑战,未来趋势将向多模态交互、自主进化和ESG投资等方向拓展。

cdfunlove的博客 203

codeforces 557B Pasha and Tea-水题

题意:总水量一定,有n个男孩,n个女孩,男孩的水是一样的,女孩的也是一样的,但是男孩的是女孩的两倍,有2*n个杯子,求最多能分给他们的总水量 分析:贪心法。不说了,就是cinTLE了。 代码: #include #include #include using namespace std; int n; double a[200010]; double m; double ans; doubl

关于学习本身 1404

【YOLO目标检测全栈实战】68 模型量化:从FP32到INT8,精度不掉,速度翻倍

摘要: 模型量化能显著提升推理速度(如YOLOv5s帧率从15FPS提升至38FPS),但需避免三大误区:1)校准集需覆盖实际场景,而非随机采样;2)敏感层(如检测头)应保留FP32精度;3)预处理必须与量化前后一致。通过混合精度量化(Backbone用INT8,检测头用FP32)和逐通道量化,可实现<1%的mAP损失。关键步骤包括校准数据准备、量化感知训练及逐层精度评估,最终在Jetson Nano等边缘设备上实现速度与精度的平衡。

企鹅码农的专属播客,分享10多年的实战案例和经验解读,包含YOLO、RT-DETR、AI等各个工作领域。 145

codeforces B. Pasha and Tea二分

http://codeforces.com/contest/557/problem/B 错了好多次。。 #include #include #include #include #include #include #include #include #include #include #include #define inf 0x3f3f3f3f #define mem(a,x) memse

liyunlonghere 639

修复漏洞Windows 2012 Server R2(CVE-2016-2183)、(CVE-2015-2808)、(CVE-2013-2566)

【代码】修复漏洞Windows 2012 Server R2(CVE-2016-2183)、(CVE-2015-2808)、(CVE-2013-2566)

路~可以走过 2772

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

Codeforces Round #311 (Div. 2)B. Pasha and Tea 水题

B. Pasha and Tea Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/557/problem/B Description Pasha decided to invite his friends to a tea party. For that occasion, he ...

weixin_34242331的博客 111

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

CodeForces - 557B Pasha and Tea(水)

B. Pasha and Tea time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Pasha decided to invite his friends to a tea p...

weixin_30632883的博客 108

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

CSU-ACM2017暑假集训比赛7 C - Pasha and Tea - CodeForces - 557B

C - Pasha and TeaPasha 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.

xiyue_jiang的博客 430

Codeforces Round #311 (Div. 2) B. Pasha and Tea

题目链接:http://codeforces.com/contest/557/problem/B 题意:给你n个boy,n个girl ,然后w表示茶壶的最大容量,然后n个茶杯,每个都有不同的容量,要求boy的茶杯里的茶水是girl的两倍,且boy和boy的容量一样,girl和girl的容量一样,问如何倒茶,求最大的倒茶量 #incl...

weixin_34261415的博客 83

B. Pasha and Tea

链接:https://codeforces.com/contest/557/problem/B Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity ofwmilliliters and2ntea cups, each c...

Luoriliming的博客 420

Codeforces 557B Pasha and Tea 【数学】

题目链接:Codeforces 557B Pasha and Tea B. Pasha and Tea time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Pasha decided to invite his friends t

世界很大 523

Codeforces 557B Pasha and Tea (思维)

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

WOLF的博客 580

codeforce Pasha and Tea

倒茶,男孩要比女孩多一倍,男孩们喝的相等,女孩们喝的相等 问最多需要倒出多少 巨恶心的一道题目,精度开到1e-12次方以上TL开到1e-12以下WA 好吧,我承认我交了20次,终于把结果测出来了 #include #include #include #include #include #include #include using namespace std; double a[30003

zhao9642的专栏 450

贪心

请朋友喝TEA问题 题目: 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. T...

weixin_44949228的博客 259
上一篇: 51Nod - 1385 凑数字(思维)
下一篇: HDU - 1698 Just a Hook (线段树区间修改模板题)
T__TSZ
博客等级 码龄10年 2粉丝 70原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值