因为读错题没有思路,没能正确求解。题目中说一个箱子最多能装俩,我却没看到。

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 ≤ 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 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

Sample Output

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}.

AC代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
using namespace std;
//#define LOCAL
#define MAX_N 100000int BOX[MAX_N];
int main()
{#ifdef LOCALfreopen("b:\\data.in.txt", "r", stdin);#endifint n , k;cin >> n >> k;for(int i = 0; i < n; i++){cin >> BOX[i] ;}//先给ans最大的量int ans = BOX[ n - 1 ];if( n <= k)cout << ans << endl ;else{//n > k && n <= 2*k时int len = n - k ;//记录前向遍历的长度int j = len ;for(int i = len-1 ; i >= 0 ; i--){ans = max( ans , BOX[i] + BOX[j++] );}cout << ans << endl ;}return 0;
}

CodeForces 604B More Cowbell相关推荐

  1. 贪心+二分 More Cowbell CodeForces - 604B

    先附上题目链接 这道题和紫书上面lrj大佬提到的坐船问题有点像.其实做贪心题我一般都是靠猜,很少证明正确性.像这题一看到题面可能有点懵,用几个样例实验一下之后就能找到规律. 就是当盒子数大于牛铃数的一 ...

  2. CodeForces 375D Tree and Queries

    传送门:https://codeforces.com/problemset/problem/375/D 题意: 给你一颗有根树,树上每个节点都有其对应的颜色,有m次询问,每次问你以点v为父节点的子树内 ...

  3. 「日常训练」Bad Luck Island(Codeforces Round 301 Div.2 D)

    题意与分析(CodeForces 540D) 是一道概率dp题. 不过我没把它当dp做... 我就是凭着概率的直觉写的,还好这题不算难. 这题的重点在于考虑概率:他们喜相逢的概率是多少?考虑超几何分布 ...

  4. 【codeforces 812C】Sagheer and Nubian Market

    [题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...

  5. CodeForces 获得数据

    针对程序的输出可以看见 CodeForces :当输入.输出超过一定字符,会隐藏内容 所以:分若干个程序进行输入数据的获取 1. 1 for (i=1;i<=q;i++) 2 { 3 scanf ...

  6. codeforces水题100道 第二十七题 Codeforces Round #172 (Div. 2) A. Word Capitalization (strings)...

    题目链接:http://www.codeforces.com/problemset/problem/281/A 题意:将一个英文字母的首字母变成大写,然后输出. C++代码: #include < ...

  7. CodeForces 595A

    题目链接: http://codeforces.com/problemset/problem/595/A 题意: 一栋楼,有n层,每层有m户,每户有2个窗户,问这栋楼还有多少户没有睡觉(只要一个窗户灯 ...

  8. codeforces A. Jeff and Digits 解题报告

    题目链接:http://codeforces.com/problemset/problem/352/A 题目意思:给定一个只有0或5组成的序列,你要重新编排这个序列(当然你可以不取尽这些数字),使得这 ...

  9. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

最新文章

  1. linux提取第一列且删除第一行(awk函数)
  2. SAP CRM和Cloud for Customer的Account merge
  3. 在python中len表示的数据类型是_python基本数据类型学习
  4. java家具网站需求分析_基于jsp的家具销售-JavaEE实现家具销售 - java项目源码
  5. python之多并发socket
  6. 大数据_Flink_数据处理_运行时架构3_yarn上作业提交流程---Flink工作笔记0018
  7. Python----进程之间共享数据(全局变量)
  8. jsp taglib指令_JSP指令–页面,包含和taglib示例
  9. 原来查询语句还有这功能,累计变量值
  10. “万物控制”是物联网下一个挑战
  11. 项目启动时,出现了Consider defining a bean of type ‘xxx’ in your configuration 问题。
  12. Matter over Wi-Fi: Raspberry Pi 4开发环境设置
  13. 河南计算机会考必背知识点,2017年河南物理高中会考知识点大全
  14. 文科大一计算机基础知识笔试答案,大学文科计算机基础知识.doc
  15. Java学习第一周总结
  16. CPU彪高分析及解决
  17. 理解闭包的前置条件—— λ演算和作用域规则
  18. python 中控考勤机实时接收打卡数据(QThread)
  19. 【STM32】OLED显示程序
  20. 微软 Teams 可以排排坐了~~ C位你要不要?

热门文章

  1. 笛卡尔积在Excel中的连接使用
  2. HTML5期末大作业:个人商城网站设计——商城个人中心网站模板(56页) 学生HTML个人网页作业作品下载 个人主页博客网页设计制作 大学生个人网站作业模板 简单个人网页制作
  3. 计算机生成目录步骤word,如何在word文档生成目录
  4. 双十一再破纪录,为什么股价却纷纷大跌:阿里跌3%、京东跌2%、拼多多跌3.03%...
  5. 网站运营:分享一些垂直社区的运营技巧
  6. java stream 理解_java Stream的理解
  7. 淘宝API 商品详情接口
  8. google log/glog
  9. Python编程 数值类型 数学计算
  10. 酷狗音乐盒2012(手机酷狗) V5.2.0(安卓)