Codeforces Round #334 (Div. 2) B. More Cowbell

Latex在VSCODE中编译报错`Recipe terminated with error. Retry building the project. Latex在VSCODE中编译报错Recipe terminated with error. Retry building the project. 1 报错提示: Recipe terminated with error 2 报错原因 大概率的原因是因为latex没有添加到系统环境变量中,所有设置的编译工具没有办法找到才出现的这种情况 3 解决方案 请按照如下方式进行系统变量的添加 对windows,win+R 然后输入sysdm.cpl 在高级中选择环境变量 找到path环境变量,将txtlive中 阅读详情
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Kevin Sun wants to move his precious collection of n cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into k boxes of a fixed size. In order to keep his collection safe during transportation, he won't place more than two cowbells into a single box. Since Kevin wishes to minimize expenses, he is curious about the smallest size box he can use to pack his entire collection.

Kevin is a meticulous cowbell collector and knows that the size of his i-th (1 ≤ i ≤ n) cowbell is an integer si. In fact, he keeps his cowbells sorted by size, so si - 1 ≤ si for any i > 1. Also an expert packer, Kevin can fit one or two cowbells into a box of size s if and only if the sum of their sizes does not exceed s. Given this information, help Kevin determine the smallest s for which it is possible to put all of his cowbells into k boxes of size s.

Input

The first line of the input contains two space-separated integers n and k (1 ≤ n ≤ 2·k ≤ 100 000), denoting the number of cowbells and the number of boxes, respectively.

The next line contains n space-separated integers s1, s2, ..., sn (1 ≤ s1 ≤ s2 ≤ ... ≤ sn ≤ 1 000 000), the sizes of Kevin's cowbells. It is guaranteed that the sizes si are given in non-decreasing order.

Output

Print a single integer, the smallest s for which it is possible for Kevin to put all of his cowbells into k boxes of size s.

Sample test(s)
input
2 1
2 5
output
7
input
4 3
2 3 5 9
output
9
input
3 2
3 5 7
output
8
Note

In the first sample, Kevin must pack his two cowbells into the same box.

In the second sample, Kevin can pack together the following sets of cowbells: {2, 3}, {5} and {9}.

In the third sample, the optimal solution is {3, 5} and {7}.

题意:给一个长度为n的有序的数列(从小到大)分成k组(如ai和aj一组分组和变为ai+aj),求分组后最大的数是多少

贪心

当n<=k时

每个数一组

当n>k时

尽量让前面的数两两一组

前面的有尽量最大的和最小的一组

#include
   
    
#include
    
     
#include
     
      
#include
      
       
using namespace std;

const int N = 100010;
int a[N];

int main(void)
{
    int n, k;
    //freopen("in.txt", "r", stdin);
    while(~scanf("%d%d", &n, &k))
    {
        int i;
        for(i = 0; i < n; i++) scanf("%d", &a[i]);
        sort(a, a+n);
        if(n <= k)
        {
            printf("%d\n", a[n-1]);
        }
        else
        {
            int tmp = n - k;
            int MAX = -1;
            for(i = 0; i < tmp; i++)
            {
                MAX = max(MAX, a[i]+a[2*tmp-i-1]);
                //printf("i=%d \t 2*tmp-i-1=%d\n", i, 2*tmp-i-1);
            }

            if(n > tmp*2) MAX = max(a[n-1], MAX);
            printf("%d\n", MAX);
        }
    }
    return 0;
}

      
     
    
   

RapidScada在windows下的安装(详细) 1.下载地址:RapidScada官网 2.版本说明 有Linux版本和Windows版本,看自己的需求下载,推荐下载最新稳定版本。 3.系统要求 4.安装前的准备(windows10) 首先打开Windows功能: 先关闭 Microsoft .NET Framework3.5的 Windows Communication Foundation 子组件。如下图: Microsoft .NET Framework配置按下图勾选: iis安装的功能: 5.安装 解压.. 阅读详情

相关推荐

泛微E8流程监控指南:如何用SQL实时追踪审批节点状态?

本文详细介绍了如何利用SQL实时监控泛微E8系统中的审批流程状态,包括核心数据表结构解析、全链路监控SQL实战以及智能预警机制设计。通过数据库直接查询和状态关联分析,帮助企业快速定位卡顿节点,提升流程效率。适用于需要优化OA系统流程管理的企业IT人员和业务主管。

weixin_30687051的博客 437

CodeForces - 604B More Cowbell

Kevin Sun wants to move his precious collection of n cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into k boxes of a fi

樱花满地集于我心,楪舞纷飞祈愿相随 604

【WILEY】wiley期刊投稿详解:从revision到Accepted全流程实例讲解

注意:包括没标注修改位置的word文件和标注了修改位置的word文件。

Everyday try to become better -Kobe Bryant 1万+

Linux 内核 TCP 窗口调优:从默认 16KB 到 128MB 的 4 个关键参数

本文详细介绍了如何通过调整Linux内核的4个关键TCP参数(tcp_rmem、tcp_wmem、rmem_max、wmem_max),将默认的16KB窗口扩展到128MB,显著提升网络吞吐量。文章包含具体配置命令、性能测试对比以及不同应用场景的优化策略,帮助解决高延迟环境下的带宽瓶颈问题。

501

【前端HTML生成条形码——MQ】

本文将展示前端HTML如何根据用户输入内容生成对应的条形码,附HTML和JS代码。代码如下(示例):

weixin_42588676的博客 1955

从零开始:手把手教你规划与部署华为FusionCompute虚拟化平台(含网络规划避坑指南)

本文详细介绍了华为FusionCompute虚拟化平台的规划与部署流程,特别针对网络规划中的常见问题提供了避坑指南。从硬件软件清单检查、网络平面配置到VRM部署方案选择,帮助用户高效完成部署并优化性能,适用于云计算环境中的虚拟化平台搭建。

weixin_28693447的博客 243

Codeforces Round #334 (604B) More Cowbell [贪心]

Kevin Sun wants to move his precious collection of n cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. —— 给出N个已排序的奶牛铃铛的大小,现在把它们装到箱子里,一个箱子最多装两个铃铛,且不能铃铛的大小和不能超过箱子大小,问在使用K个箱子的前提下,问盒子最小多大。

Asuna_acmer 844

基于STM32 FOC下桥三电阻采样方式的电机相电流重构方法

如何提高三电阻采样的调制率

wanrenqi的博客 9193

【Codeforces Round 334 (Div 2)B】【贪心】More Cowbell n个物品装进m个箱子,每个箱子最多放2个物品 要求箱子空间尽可能小

B. More Cowbell time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Kevin Sun wants to move his precious collecti

snowy_smile的博客 2044

OpenClaw实战系列01:OpenClaw接入飞书机器人全接入指南 + Ollama本地大模型

通过 OpenClaw + Ollama + 飞书的组合,我们成功搭建了一个完全私有、免费、可定制的AI助理。它不仅能在日常聊天中提供帮助,还能通过OpenClaw强大的“技能”体系,真正去操作你的电脑、管理文件、甚至执行代码。这套方案将数据留在本地,既保证了隐私安全,又锻炼了动手能力。现在,去给你的AI助理添加更多酷炫的技能吧!

PeterPan的博客 1万+

从Safety Manual到系统安全概念

本文系统阐述了构建功能安全"证据链"的工程化方法论,核心要点包括:1)建立"风险→对策→验证→证据"闭环链条;2)SafetyManual和FMEDA作为关键证据支撑点,前者界定系统安全边界,后者量化诊断覆盖率;3)通过四步法继承芯片安全机制并扩展至系统级;4)形成"设计-分析-验证"三维闭环体系,包括安全目标、技术实现和验证矩阵;5)强调证据链闭环对安全认证和OEM认可的重要性。该方法论实现了从理论要求到工程实践的完整转化,确保安全设计可验证、可

VehSwHwDeveloper的博客 721

codeforces 604B (贪心)

B. More Cowbell time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Kevin Sun wants to move his precious collec

morejarphone~ 670

华为Ascend C算子开发能力认证(中级)(个人记录,有完整代码,已通过认证,仅供参考)

本文介绍了在昇腾NPU环境下实现Sigmoid算子的完整流程。首先需要在华为云ModelArts-Notebook或开发者套件上搭建环境,要求CANN版本为8.0.0.beta1。主要内容包括:1)实现SigmoidCustom算子的kernel侧核函数代码;2)完成host侧Tiling结构体实现;3)支持Float16数据类型。代码实现部分详细展示了核函数计算流程、数据拷贝和牛顿迭代优化方法。最后介绍了编译部署流程,包括环境配置、代码上传、编译执行等步骤,并提供了提交规范说明。该实现通过调用Ascend

qq_73044452的博客 1107

Codeforces Round #334 (Div. 2) B. More Cowbell (贪心)

B. More Cowbell time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Kevin Sun wants to move his precious collecti

滴水穿石,慢慢积累,总会有成果 671

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

Codeforces Round #334 (Div. 2) B. More Cowbell

数学。。。

代码改变世界 631

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

2026年性能测试工具选型指南:JMeter、k6、Locust等13款工具深度对比

性能测试是保障系统稳定性的关键环节,其核心在于通过模拟真实流量评估系统瓶颈。压测工具作为执行载体,需具备脚本编写、场景调度和结果分析能力。选型时需权衡学习成本、维护成本和资源效率,并关注与可观测性体系的融合。在云原生和CI/CD普及的背景下,压测即代码和实时监控成为趋势。本文基于2026年最新实践,深入对比JMeter、k6、Locust、Gatling、LoadRunner等主流工具,从底层逻辑到实操技巧,助你构建高效压测体系。

weixin_34025051的博客 190

Codeforces Round #334 (Div. 2) B. More Cowbell 二分

B. More Cowbell Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/problem/B Description Kevin Sun wants to move his precious collection ofncowbells from Naperthril...

weixin_30412013的博客 127

Codeforces Round #334 (Div. 2)B. More Cowbell(二分+贪心)

题目链接 题意:给你n个物品的大小,和k个盒子,每个盒子最多只能放2个物品。 物品的大小按照升序给出,问你最小的盒子是多大 解答:二分盒子的大小S,然后判断下体积是S时需要的盒子数量是不是小于K的。这个地方要贪心,正确的方法是把体积大的和体积小的放在一起 #define CF #ifndef CF #include<cstdio> #include<algorithm> #include<cs

qwesde 477

Codeforces Round #334 (Div. 2) B. More Cowbell (贪心)

传送门:B. More Cowbell 描述: B. More Cowbell time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Kev

魔笛手的博客 312

Codeforces Round #334 (Div. 2)-More Cowbell(贪心模拟)

B. More Cowbell time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Kevin Sun wants to move his precious collection of n

梧桐下的四叶草 505

Codeforces Round #334 (Div. 2)

A. Uncowed Forces 【题意】给定公式,带入数值 【分析】按题目中说的来,注意精度 【代码】 #include<cstdio> #include<algorithm> #include<iostream> #include<cmath> using namespace std; int main (vo...

An55511的博客 75

Codeforces Round #334 B. More Cowbell (二分 + 贪心)

题意: k个箱子装n个物品(n≤2∗k≤105),每个箱子最多装2个物品,求最小的满足要求的箱子的体积k个箱子装n个物品 (n \leq 2 * k \leq 10 ^ 5), 每个箱子最多装2个物品, 求最小的满足要求的箱子的体积 分析: 小的能装大的也可以装,满足单调性可以二分,check的时候贪心一下,肯定是一大一小装才最好嘛,注意边界小的能装大的也可以装, 满足单调性可以二分, ch

TaoSama's Microcosm 385
上一篇: Codeforces Round #334 (Div. 2) A. Uncowed Forces
下一篇: Codeforces Round #334 (Div. 2) C. Alternative Thinking
zhaohuc
博客等级 码龄11年 5粉丝 110原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值