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 ...
随机推荐
- BZOJ1935或洛谷2163 [SHOI2007]园丁的烦恼
BZOJ原题链接 洛谷原题链接 很容易想到二维前缀和. 设\(S[i][j]\)表示矩阵\((0, 0)(i, j)\)内树木的棵数,则询问的矩形为\((x, y)(xx, yy)\)时,答案为\(S ...
- egg 为企业级框架和应用而生, 阿里出品
https://eggjs.org/zh-cn/intro/ egg 是什么? egg 为企业级框架和应用而生,我们希望由 egg 孕育出更多上层框架,帮助开发团队和开发人员降低开发和维护成本. 设计 ...
- UI设计教程分享:Ps合成炫酷机械姬
本次给大家分享一个通过PS合成一个炫酷的机械姬,在这个教程里给大家展示图像的色彩处理.人物光影塑造和创意实现及细节处理,教程比较简单,创意十足,看过<机械姬>电影的同学们一定知道这个有多炫 ...
- [Robot Framework] SikuliLibrary的关键字执行依赖java进程,但是上次的java进程如果没有杀掉,robot framework控制台的日志出不来,怎么办?
如果在suite的setup里面杀掉java进程:AutoItLibrary.Run | taskkill /F /IM java.exe 执行sikuli的关键字会报这样的错误: Connectio ...
- DbUtils类的添加,修改,删除
package cn.jy.demo; import java.sql.Connection;import java.sql.SQLException; import org.apache.commo ...
- regexper-正则表达式检验
https://regexper.com 例如:输入 \s.?\w{1,3}(\d(\W)(#?\d{1..4}))
- [js]获取网页屏幕可见区域高度
document.body.clientWidth ==> BODY对象宽度 document.body.clientHeight ==> BODY对象高度 document.docume ...
- springMVC学习一 工作机制
springMVC下面的四大组件: (1)DispatcherServlet : 前端控制器,接收所有请求 ,并把请求路径和请求参数解析出来,本质是一个servlet在web.xml中配置 (如果配置 ...
- 子数整数(P1151&NOIP水题测试(2017082301))
题目链接:子数整数 水题,不解释,自己看代码: #include<bits/stdc++.h> using namespace std; int main(){ int k; scanf( ...
- 796. Rotate String
class Solution { public: bool rotateString(string A, string B) { if(A.length()==B.length()&& ...