【CodeForces 604B】F - 一般水的题1-More Cowbe
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
2 1
2 5
7
4 3
2 3 5 9
9
3 2
3 5 7
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的更多相关文章
- Codeforces 1214 F G H 补题记录
翻开以前打的 #583,水平不够场上只过了五题.最近来补一下题,来记录我sb的调试过程. 估计我这个水平现场也过不了,因为前面的题已经zz调了好久-- F:就是给你环上一些点,两两配对求距离最小值. ...
- Codeforces Round #378 (Div. 2) D题(data structure)解题报告
题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...
- CodeForces.158A Next Round (水模拟)
CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...
- http://codeforces.com/gym/100623/attachments E题
http://codeforces.com/gym/100623/attachments E题第一个优化它虽然是镜像对称,但它毕竟是一一对称的,所以可以匹配串和模式串都从头到尾颠倒一下第二个优化,与次 ...
- Codeforces 515C 题解(贪心+数论)(思维题)
题面 传送门:http://codeforces.com/problemset/problem/515/C Drazil is playing a math game with Varda. Let’ ...
- Codeforces 828B Black Square(简单题)
Codeforces 828B Black Square(简单题) Description Polycarp has a checkered sheet of paper of size n × m. ...
- Codeforces 959 F. Mahmoud and Ehab and yet another xor task
\(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...
- Codeforces 835 F. Roads in the Kingdom
\(>Codeforces\space835 F. Roads in the Kingdom<\) 题目大意 : 给你一棵 \(n\) 个点构成的树基环树,你需要删掉一条环边,使其变成一颗 ...
- Codeforces 731 F. Video Cards(前缀和)
Codeforces 731 F. Video Cards 题目大意:给一组数,从中选一个数作lead,要求其他所有数减少为其倍数,再求和.问所求和的最大值. 思路:统计每个数字出现的个数,再做前缀和 ...
随机推荐
- Redis漏洞?阿里云被攻击!
今天运维那边过来说阿里云服务器进程被占用很多,后来查了一下进程发现了这个玩意: 小编我看不懂,经运维先森仔细研究,发现这是被注入进来的一个进程,服务器被当成了肉鸡,专门用来跑比特币的,这样对方就不需要 ...
- 权限框架 - shiro 自定义realm
上篇文章中是使用的默认realm来实现的简单登录,这仅仅只是个demo,真正项目中使用肯定是需要连接数据库的 首先创建自定义realm文件,如下: 在shiro中注入自定义realm的完全限定类名: ...
- 学习web前端三个月感悟
总结一下自己学习前端三个月的进步和不足: 其实也算机遇,开学时,便有一个PHP培训,只记得当时拿到培训课程的时候,第一感觉就是 好难,什么留言板制作,学生信息系统的制作,navicat和PHP结合使用 ...
- 27Spring_的事务管理_银行转账业务加上事务控制_基于tx.aop进行声明式事务管理
上一篇文章中,银行转账业务没有使用事务,会出现问题,所以这篇文章对上篇文章出现的问题进行修改. 事务 依赖 AOP , AOP需要定义切面, 切面由Advice(通知) 和 PointCut(切点) ...
- PHP5.5 + IIS + Win7的配置
PHP运行环境主要分windows环境和linux环境,本文主要简单介绍下我自己的配置,其他就不一一说明了. windows环境 方式一:.Apache的安装配置:2.MySQL的安装配置,可安装ph ...
- C# == equals 本质理解
using System; using System.Diagnostics; using System.Text; using System.Collections; using System.Co ...
- 面试准备(三) Java 异常类层次结构
在Java中,异常分为受检查的异常,与运行时异常. 两者都在异常类层次结构中.这类容易出选择题 考试你是否掌握了异常类并清楚哪些异常类必须捕获 下面的图展示了Java异常类的继承关系. 图1 粉红色的 ...
- js字符串截取函数slice()、substring()、substr()
摘要 在js中字符截取函数有常用的三个slice().substring().substr()了,下面我来给大家介绍slice().substring().substr()函数在字符截取时的一些用法与 ...
- [CareerCup] 7.6 The Line Passes the Most Number of Points 经过最多点的直线
7.6 Given a two-dimensional graph with points on it, find a line which passes the most number of poi ...
- 使用线程池模拟处理耗时任务,通过websocket提高用户体验
前言 在文章开始之前,询问一下大家平时工作中后端处理批量任务(耗时任务)的时候,前端是如何告知用户任务的执行情况的? 楼主对这个问题想了下,决定使用websokect将这一过程展现给用户. 于是就有了 ...