G - Christmas Play
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的更多相关文章
- Storyboards Tutorial 03
这一节主要介绍segues,static table view cells 和 Add Player screen 以及 a game picker screen. Introducing Segue ...
- 文件图标SVG
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink ...
- Father Christmas flymouse--POJ3160Tarjan
Father Christmas flymouse Time Limit: 1000MS Memory Limit: 131072K Description After retirement as c ...
- poj 3013 Big Christmas Tree (最短路径Dijsktra) -- 第一次用优先队列写Dijsktra
http://poj.org/problem?id=3013 Big Christmas Tree Time Limit: 3000MS Memory Limit: 131072K Total S ...
- poj 3013 Big Christmas Tree Djistra
Big Christmas Tree 题意:图中每个节点和边都有权值,图中找出一颗树,树根为1使得 Σ(树中的节点到树根的距离)*(以该节点为子树的所有节点的权值之和) 结果最小: 分析:直接求出每个 ...
- POJ 3013 Big Christmas Tree(最短Dijkstra+优先级队列优化,SPFA)
POJ 3013 Big Christmas Tree(最短路Dijkstra+优先队列优化,SPFA) ACM 题目地址:POJ 3013 题意: 圣诞树是由n个节点和e个边构成的,点编号1-n. ...
- POJ Big Christmas Tree(最短的基础)
Big Christmas Tree 题目分析: 叫你构造一颗圣诞树,使得 (sum of weights of all descendant nodes) × (unit price of the ...
- aoj 2226 Merry Christmas
Merry Christmas Time Limit : 8 sec, Memory Limit : 65536 KB Problem J: Merry Christmas International ...
- 【Kickstart】2017 Round (Practice ~ G)
Practice Round Problem A Country Leader (4pt/7pt) Problem B Vote (5pt/8pt) Problem C Sherlock and Pa ...
随机推荐
- 转载(windows下安装mysql)
转载请声明出处:http://blog.csdn.net/u013067166/article/details/49951577 最近重装了系统,去MySQL官网下载了最新的M ...
- 让eclipse调试和豌豆荚并存
豌豆荚有一个设置 设置->高级设置->开发者模式 勾上开发者模式 确定. 你什么手机的驱动都不用安装了. 就可以直接使用豌豆荚,也可以使用eclipse进行调试.
- UI设计初学者必备的工具以及学习路线(附思维导图)
今天千锋UI设计小编着重为大家介绍5个学习ui设计必须要会的工具和软件以及UI设计学习路线,希望能对大家所帮助. UI设计必要的工具和软件 1.PS 图像处理合成软件 ui设计核心软件,强大的图像处理 ...
- JVM 目录
JVM 目录 走进 JVM Java 虚拟机规范(Oracle 官网) Java 虚拟机规范(Java SE 7 中文版) (周志明等译) 周志明,深入理解Java虚拟机[M],机械工业出版社,201 ...
- install virtualenv
$ [sudo] pip install virtualenv $ mkdir ~/envs $ virtualenv ~/envs/lsbaws/ $ cd ~/envs/lsbaws/ $ ls ...
- mysql中的handler_read_%
mysql> show status like 'handler_read_%'; +-----------------------+-------+ | Variable_name | Val ...
- 2018.12.31 NOIP训练 czy的后宫5(树形dp)
传送门 题意:给一棵有根树,树有点权,最多选出mmm个点,如果要选一个点必须先选其祖先,问选出来的点权和最大值是多少. 直接背包转移就行了. 代码
- jQuery Growl插件(消息提醒)
ps:菜鸟教程 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <s ...
- mount 移动硬盘出现的各种小问题
1.fdisk -l 查看硬盘是否存在 2.新建要挂载硬盘的文件夹 mkdir /disk (如果想要挂载到已存在的目录就不要新建了) 3.挂载硬盘:mount /dev/sdc /disk 4 ...
- IntelliJ IDEA 2017版 spring-boot 拦截器的操作三种方式
一.注解方式 @WebServlet(urlPatterns = "/myServlet") public class MyServlet extends HttpServlet ...