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 #378 (Div. 2) D题(data structure)解题报告

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

  3. CodeForces.158A Next Round (水模拟)

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

  4. http://codeforces.com/gym/100623/attachments E题

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

  5. Codeforces 515C 题解(贪心+数论)(思维题)

    题面 传送门: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. Mahmoud and Ehab and yet another xor task

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

  8. Codeforces 835 F. Roads in the Kingdom

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

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

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

随机推荐

  1. mysql乱码的好文

    1. http://www.blogjava.net/wldandan/archive/2007/09/04/142669.html 2. http://www.111cn.net/database/ ...

  2. VS2013无法启动 IIS Express Web解决办法

    不要勾选[覆盖应用程序根URL(U)],或让[覆盖应用程序根URL(U)]下面的输入框和上面的输入框的地址一样! 使用VS2013有一段时间了,因前期都是编写C/S程序,没有使用到B/S调试器.前几日 ...

  3. javascript获取当前的时间戳

    JavaScript 获取当前时间戳:第一种方法: var timestamp = Date.parse(new Date()); 结果:1280977330000第二种方法: var timesta ...

  4. 修改sqlserver2008默认的数据库文件保存路径

    在SSMS(SQL Server Management Studio)中,右键服务器,然后选择属性. 然后数据库设置,再配置数据库默认位置 方法二,直接使用sql语句修改 USE [master] G ...

  5. SEO在网页制作中的应用

    1.什么是SEOSEO(Search Engine Optimization)中文意译为“搜索引擎优化”.SEO是指通过网站内部调整优化及站外优化,使网站满足搜索引擎收录排名需求,在搜索引擎中提高关键 ...

  6. Android使用AttributeSet自定义控件的方法

    所谓自定义控件(或称组件)也就是编写自己的控件类型,而非Android中提供的标准的控件,如TextView,CheckBox等等.不过自定义的控件一般也都是从标准控件继承来的,或者是多种控件组合,或 ...

  7. Winform调用百度地图接口

    using System; using System.IO; using System.Collections.Generic; using System.ComponentModel; using ...

  8. C#中小数点后保留两位小数,四舍五入的函数及使用方法

    Math.Round(45.367,2)     //Returns   45.37 Math.Round(45.365,2)     //Returns   45.36 C#中的Round()不是我 ...

  9. scrapy 爬取 useragent

    useragentstring.com 网站几乎廊括了所有的User-Agent,刚学了scrapy,打算那它练手,把上面的 user-agent 爬取下来. 本文只爬取常见的 FireFox, Ch ...

  10. python爬虫中文网页cmd打印出错问题解决

    问题描述 用python写爬虫,很多时候我们会先在cmd下先进行尝试. 运行爬虫之后,肯定的,我们想看看爬取的结果. 于是,我们print... 运气好的话,一切顺利.但这样的次数不多,更多地,我们会 ...