【CodeForces 604B】F - 一般水的题1-More Cowbe

时间:2022-09-06 14:40:01

Description

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 ≤ in) cowbell is an integer si. In fact, he keeps his cowbells sorted by size, so si - 1si 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 ≤ s1s2 ≤ ... ≤ 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 Input

Input

2 1
2 5

Output

7

Input

4 3
2 3 5 9

Output

9

Input

3 2
3 5 7

Output

8

Hint

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个箱子,每个箱子可以装1~2个牛铃,每个牛铃大小不同,所有箱子都是s容量,求最小的s可以装所有的牛铃。

贪心,读入的数据已经排好,将k个牛铃放进k个箱子,每个箱子一个,那么还有n-k个牛铃必须放到已经装有1个的箱子里,那么就有n-k个箱子是装两个的。我们让只装一个牛铃的箱子尽量装大的,要装两个的箱子,装最小的(n-k)*2个里面最大的和最小的,第二大和第二小……

#include<stdio.h>
#include<algorithm>
using namespace std;
long long n,k,s[],maxs;
int main(){
scanf("%lld%lld",&n,&k);
for(long long i=;i<n;i++)
scanf("%lld",&s[i]);
maxs=s[n-];
for(long long i=;i<n-k;i++)
maxs=max(maxs,s[i]+s[(n-k)*-i-]); printf("%lld\n",maxs);
return ;
}

【CodeForces 604B】F - 一般水的题1-More Cowbe的更多相关文章

  1. Codeforces 1214 F G H 补题记录

    翻开以前打的 #583,水平不够场上只过了五题.最近来补一下题,来记录我sb的调试过程. 估计我这个水平现场也过不了,因为前面的题已经zz调了好久-- F:就是给你环上一些点,两两配对求距离最小值. ...

  2. Codeforces Round &num;378 &lpar;Div&period; 2&rpar; D题(data structure)解题报告

    题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...

  3. CodeForces&period;158A Next Round &lpar;水模拟&rpar;

    CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...

  4. http&colon;&sol;&sol;codeforces&period;com&sol;gym&sol;100623&sol;attachments E题

    http://codeforces.com/gym/100623/attachments E题第一个优化它虽然是镜像对称,但它毕竟是一一对称的,所以可以匹配串和模式串都从头到尾颠倒一下第二个优化,与次 ...

  5. Codeforces 515C 题解&lpar;贪心&plus;数论&rpar;&lpar;思维题&rpar;

    题面 传送门:http://codeforces.com/problemset/problem/515/C Drazil is playing a math game with Varda. Let’ ...

  6. Codeforces 828B Black Square(简单题)

    Codeforces 828B Black Square(简单题) Description Polycarp has a checkered sheet of paper of size n × m. ...

  7. Codeforces 959 F&period; Mahmoud and Ehab and yet another xor task

    \(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...

  8. Codeforces 835 F&period; Roads in the Kingdom

    \(>Codeforces\space835 F. Roads in the Kingdom<\) 题目大意 : 给你一棵 \(n\) 个点构成的树基环树,你需要删掉一条环边,使其变成一颗 ...

  9. Codeforces 731 F&period; Video Cards(前缀和)

    Codeforces 731 F. Video Cards 题目大意:给一组数,从中选一个数作lead,要求其他所有数减少为其倍数,再求和.问所求和的最大值. 思路:统计每个数字出现的个数,再做前缀和 ...

随机推荐

  1. Oracle读写分离架构

    读写分离是架构分布式系统的一个重要思想.不少系统整体处理能力并不能同业务的增长保持同步,因此势必会带来瓶颈,单纯的升级硬件并不能一劳永逸.针对业务类型特点,需要从架构模式上进行一系列的调整,比如业务模 ...

  2. POJ 1625 Censored&excl;&lpar;大数&plus;DP&rpar;

    题目链接 这题,真心木啥意思,就是数据里貌似字符有负数,注意gets读入.. #include <iostream> #include <cstring> #include & ...

  3. &lbrack;Papers&rsqb;NSE&comma; &dollar;u&lowbar;3&dollar;&comma; Lebesgue space &lbrack;Jia-Zhou&comma; NARWA&comma; 2014&rsqb;

    $$\bex u_3\in L^\infty(0,T;L^\frac{10}{3}(\bbR^3)). \eex$$

  4. L008-oldboy-mysql-dba-lesson08

    L008-oldboy-mysql-dba-lesson08 xtrabackup安装 [root@web01 installer]# wget https://www.percona.com/dow ...

  5. oracle忘记用户密码

    在cmd命令行下输入sqlplus / as sysdba alter user system identified by abc; 就可以将system用户的密码改成abc了. alter user ...

  6. failure injection

    (1)malloc穷尽的情况: 假设下面的代码是测试代码,里面含有被测函数fmalloc,其中含有一个malloc语句,在一般情况下,是很难走到malloc失败的分支的,因为很难模拟系统内存耗尽的情况 ...

  7. CSS3 Background-clip

    上一节在<CSS3 background-size>详细的介绍了CSS3为background新增属性之一,今天和大家一起来学习CSS3中有关于Background的第二新属性Backgr ...

  8. div成圆形分布

    1.  css3 ul{                 width: 200px;                 height: 200px;                 background ...

  9. eclipse安装阿里代码扫描插件

    1.首先打开eclipse软件,点击工具栏上的Help,选择Install New Soft进行安装新的插件. 2.进入插件安装界面,点击Add,弹出插件地址填写界面,也可以直接在市场上搜索关键字al ...

  10. Linux gcj命令

    一.简介 GCJ是GNU的Java编译器,可以把java程序编译成本地代码,编译成功后的可执行文件不再需要jre就可直接运行,编译成本地后的程序运行速度有所提高,缺点是生成后的文件较大. 参考: ht ...