Description

My kid's kindergarten class is putting up a Christmas play.  (I hope he gets the lead role.)  The kids are all excited, but the teacher has a lot of work.  She has to produce costumes for a scene with K soldiers.  She wants to buy all the costumes in the same size, allowing for some small amount of length alteration to be done by the kids' parents later.  So she has taken all the kids' height measurements.  Can you help her select K kids from her class of N to play the soldier role, such that the height difference between the tallest and shortest in the group is minimized, and alternations will be easiest?  Tell her what this minimum difference is.
 
 
INPUT
The first line contains the number of test cases T. T test cases follow each containing 2 lines.
 
The first line of each test case contains 2 integers N and K.
The second line contains N integers denoting the height of the N kids.
 
OUTPUT
Output T lines, each line containing the required answer for the corresponding test case.
 
CONSTTRAINTS
T <= 30
1 <= K <= N <= 20000
1 <= height <= 1000000000
 
SAMPLE INPUT
3
3 1
2 5 4  
3 2
5 2 4  
3 3
2 5 4  
 
 
SAMPLE OUTPUT
0
1
3
 
EXPLANATION
In
the first test case, the teacher needs to only select 1 kid and hence
she can choose any kid since the height difference is going to be 0.
In the second test case, the teacher can choose kids with height 4 and 5.
In the third test case, the teacher is forced to choose all 3 kids and hence the answer = 5-2 = 3

题意:3 2   三个人   间隔为2
        5 2 4  三个人的身高    求间隔为2的最小身高差

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm> using namespace std; int main()
{
int t,n,d;
int a[];
while(~scanf("%d",&t)) while(t--)
{
scanf("%d%d",&n,&d);
for(int i=; i<n; i++)
scanf("%d",&a[i]);
sort(a,a+n);
int sum=;
for(int i=; i<n-d+; i++)
{
//cout<<a[i]<<' '<<a[i+d-1]<<"!!!!!!!!"<<endl;
if(sum>(a[i+d-]-a[i]))
sum=(a[i+d-]-a[i]);
}
printf("%d\n",sum);
}
return ;
}

G - Christmas Play的更多相关文章

  1. Storyboards Tutorial 03

    这一节主要介绍segues,static table view cells 和 Add Player screen 以及 a game picker screen. Introducing Segue ...

  2. 文件图标SVG

    ​<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink ...

  3. Father Christmas flymouse--POJ3160Tarjan

    Father Christmas flymouse Time Limit: 1000MS Memory Limit: 131072K Description After retirement as c ...

  4. poj 3013 Big Christmas Tree (最短路径Dijsktra) -- 第一次用优先队列写Dijsktra

    http://poj.org/problem?id=3013 Big Christmas Tree Time Limit: 3000MS   Memory Limit: 131072K Total S ...

  5. poj 3013 Big Christmas Tree Djistra

    Big Christmas Tree 题意:图中每个节点和边都有权值,图中找出一颗树,树根为1使得 Σ(树中的节点到树根的距离)*(以该节点为子树的所有节点的权值之和) 结果最小: 分析:直接求出每个 ...

  6. POJ 3013 Big Christmas Tree(最短Dijkstra+优先级队列优化,SPFA)

    POJ 3013 Big Christmas Tree(最短路Dijkstra+优先队列优化,SPFA) ACM 题目地址:POJ 3013 题意:  圣诞树是由n个节点和e个边构成的,点编号1-n. ...

  7. POJ Big Christmas Tree(最短的基础)

    Big Christmas Tree 题目分析: 叫你构造一颗圣诞树,使得 (sum of weights of all descendant nodes) × (unit price of the ...

  8. aoj 2226 Merry Christmas

    Merry Christmas Time Limit : 8 sec, Memory Limit : 65536 KB Problem J: Merry Christmas International ...

  9. 【Kickstart】2017 Round (Practice ~ G)

    Practice Round Problem A Country Leader (4pt/7pt) Problem B Vote (5pt/8pt) Problem C Sherlock and Pa ...

随机推荐

  1. BZOJ3669 膜法森林 - LCT

    Solution 非常妙的排序啊... 仔细想想好像确实能够找出最优解QUQ 先对第一关键字排序, 在$LCT$ 维护第二关键字的最大值 所在的边. 添边时如果$u, v$ 不连通 就直接加边.  如 ...

  2. Centos安装配置Postfix邮件服务器--网址

    http://www.haiyun.me/archives/centos-install-postfix.html http://blog.csdn.net/liuyunfengheda/articl ...

  3. C#在Winform程序中显示QQ在线状态

    首先,引入必要的命名空间 using System.Windows.Forms;  using System.Net; 其次,在Form中拖入一个PictureBox控件,并设置其SizeMode为A ...

  4. 基于centos6.5 hbase 集群搭建

    注意本章内容是在上一篇文章“基于centos6.5 hadoop 集群搭建”基础上创建的 1.上传hbase安装包 hbase-0.96.2-hadoop2 我的目录存放在/usr/hadoop/hb ...

  5. IOS初级:app的启动图像

    1,准备若干张适合不同设备满屏幕的图像 这里补充说明一下图像的命名方法: iphone4屏幕 Default@2x.png iphone5屏幕 Default-568h@2x.png  (568*2即 ...

  6. Tomcat新问题 还没有解决:the apr based apache tomcat native librariy which allows optional perf...........

     问题信息详细: 2012-5-18 18:41:54 org.apache.catalina.core.AprLifecycleListener init 信息: The APR based Apa ...

  7. CRC-32的原理和实现

    /* crc32.c -- compute the CRC-32 of a data stream * Copyright (C) 1995-2002 Mark Adler * For conditi ...

  8. java 中java.util.Arrays类---常用函数记录

    java.util.Arrays主要是用来对数组进行操作的类,主要包括以下方法: 1.数组转化列表,得到固定大小的列表,Arrays.asList(...): public static <T& ...

  9. 【WebService】WebService之CXF和Spring整合(六)

    前面介绍了WebService与CXF的使用,项目中我们经常用到Spring,这里介绍CXF与Spring整合 步骤 1.创建一个Maven Web项目,可以参照:[Maven]Eclipse 使用M ...

  10. [html]Sublime Text添加插件

    今天想在Sublime Text(简称ST)内编写HTML后直接使用浏览器看效果,想添加View in Browser插件,然后遇到奇怪的问题添加插件直接报"找不到有用的插件" 一 ...