题目链接:http://codeforces.com/contest/604/problem/B

题意:n个数字,k个盒子,把n个数放入k个盒子中,每个盒子最多只能放两个数字,问盒子容量的最小值是多少

(当时没有看清题意,每个盒子最多只能放入两个数字)n个数字的输入是从小到大

题目分类:贪心

代码:

#include<bits/stdc++.h>

using namespace std;
int a[];
int b[]; int main()
{
int n,k;
cin>>n>>k;
for(int i=;i<=n;i++)
{
cin>>a[i];
}
if(n<=k)
{
cout<<a[n]<<endl;
return 0;
}
for(int j=;j<=k;j++) //先把大的放进去
{
b[j]=a[n-j+];
}
sort(b+,b+k+);
n=n-k;
for(int i=1;i<=k&&n>=1;i++) //代码的关键部分
{
b[i]+=a[n];
n--
;
}

sort(b+,b+k+);
printf("%d\n",b[k]);
return ;
}

codeforces 604B More Cowbell的更多相关文章

  1. 【31.72%】【codeforces 604B】More Cowbell

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

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

    Description Kevin Sun wants to move his precious collection of n cowbells from Naperthrill to Exeter ...

  3. codeforce 604B More Cowbell

    题意:n个球,分成k堆.问堆的最大值的最小. #include <bits/stdc++.h> typedef long long ll; using namespace std; int ...

  4. CF 604B More Cowbell#贪心

    (- ̄▽ ̄)-* //把最大单独放,然后第二大的和最小的放一起,第三大的和第二小的放一起 //由此类推,求最大值,即为盒的最小值 #include<iostream> #include&l ...

  5. 「日常训练」More Cowbell(Codeforces Round #334 Div.2 B)

    题意与分析(CodeForces 604B) 题意是这样的:\(n\)个数字,\(k\)个盒子,把\(n\)个数放入\(k\)个盒子中,每个盒子最多只能放两个数字,问盒子容量的最小值是多少(水题) 不 ...

  6. codeforces604B

    More Cowbell CodeForces - 604B Kevin Sun wants to move his precious collection of n cowbells from Na ...

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

    B. More Cowbell Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/probl ...

  8. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  9. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

随机推荐

  1. 基于visual Studio2013解决C语言竞赛题之1003字母打印

        题目 解决代码及点评 ///************************************************************************/ ...

  2. Math.random与java.util.Random的差别

    今天在做一道习题时想到了Math.random()与Random类有什么区别,查阅了一些资料,感觉讲的不是太好. 首先两者的区别是一个是方法,一个是类. 其实前者的实现借助与后者.大家可以看一下Mat ...

  3. opencv实现连通域

    在本文中使用图像连通域统计使用opencv中的cvFloodFill方法,可是在cvFloodFill方法中CvConnectedComp參数无法返回详细点坐标位置信息,找了些资料.给CvSeq分配空 ...

  4. IT忍者神龟之Oracle DBA经常使用查询吐血列举

    –1. 查询系统全部对象 select owner, object_name, object_type, created, last_ddl_time, timestamp, status from ...

  5. QT update和repaint的区别

    void QWidget::repaint ( int x, int y, int w, int h, bool erase = TRUE ) [槽] 通过立即调用paintEvent()来直接重新绘 ...

  6. 【iOS】网页中调用JS与JS注入

    非常多应用为了节约成本,做出同一时候在Android与iOS上都能使用的界面,这时就要使用WebView来做.Android和IOS上都有WebView,做起来非常省事.当然这时就要考虑怎样在Andr ...

  7. java运行脚本语言demo

    public class Test { /** * @param args * @throws IOException  */ public static void main(String[] arg ...

  8. sqlserver 存储过程实例

    ALTER PROC [dbo].[SP_mm_NS] (        @ID        NVARCHAR(60),        @ReturnCode    NVARCHAR(30) OUT ...

  9. asp.net下用js实现弹出子窗口选定值并返回

    对应上一篇博客代码: 父页面: <head runat="server"> <meta http-equiv="X-UA-Compatible" ...

  10. wince平台下使用log4net记录日志

    前面我写过一篇文章是来介绍windows平台下开发软件使用log4net来记录日志的,详情请参考:用一个简单的示例说明日志记录组件log4net的使用. 我们在wince平台下开发程序也一样需要日志文 ...