A. Puzzles

Time Limit: 2 Sec  Memory Limit: 60 MB

题目连接

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5373

Description

The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her n students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces).

The shop assistant told the teacher that there are m puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of f1 pieces, the second one consists of f2 pieces and so on.

Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let A be the number of pieces in the largest puzzle that the teacher buys and B be the number of pieces in the smallest such puzzle. She wants to choose such n puzzles that A - B is minimum possible. Help the teacher and find the least possible value of A - B.

Input

The first line contains space-separated integers n and m (2 ≤ n ≤ m ≤ 50). The second line contains m space-separated integers f1, f2, ..., fm (4 ≤ fi ≤ 1000) — the quantities of pieces in the puzzles sold in the shop.

Output

Print a single integer — the least possible difference the teacher can obtain.

Sample Input

4 6
10 12 10 7 5 22

Sample Output

v

HINT

Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5.

题意

给你N个数,然后让你选M个,让这M个数中的最大值减去最小值的这个值,最小

问这个最小值是多少

题解:

拍一下序,然后暴力搞一搞就好

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 2001
#define mod 10007
#define eps 1e-9
//const int inf=0x7fffffff; //无限大
const int inf=0x3f3f3f3f;
/* */
//**************************************************************************************
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int a[maxn];
bool cmp(int c,int d)
{
return c>d;
}
int main()
{
int n=read(),m=read();
for(int i=;i<m;i++)
a[i]=read();
int mi=inf;
sort(a,a+m,cmp);
for(int i=;i+n-<m;i++)
mi=min(a[i]-a[i+n-],mi);
printf("%d\n",mi);
}

最新文章

  1. zabbix3.x web设置手册(2)
  2. (转)IIS设置优化(需根据服务器性能,调整具体参数值)
  3. poj 1742 Coins
  4. Linux查看磁盘块大小
  5. C文件函数总结
  6. eclipse for mac 快捷键
  7. PHPExcel生成或读取excel文件
  8. spring cloud 入门系列六:使用Zuul 实现API网关服务
  9. webpack打包优化之外部扩展externals的实际应用
  10. python自动化开发-[第三天]-编码,函数,文件操作
  11. 看淘宝营销api 文档有感
  12. C# 操作符 &lt;&lt; 与 &gt;&gt;
  13. 一个linux内核编译时遇到的perl语法导致的编译问题解决
  14. 按装 autoconf 出现 需要安装m4-1.4.16.tar.gz的错误
  15. SpringBatch的初步了解
  16. 用JavaScript来生成HTML
  17. day 08 函数
  18. 作业调度系统quartz.net
  19. Swift图书展示项目笔记
  20. HyperLogLog in Practice: Algorithmic Engineering of a State of The Art Cardinality Estimation Algorithm

热门文章

  1. ASP.NET MVC 防止跨站请求伪造(CSRF)攻击的方法
  2. Isolate randomforest检测异常点的非监督方法
  3. jpql和sql的区别
  4. Service(二):通信
  5. MyBatis框架的基本使用
  6. TObject、TPersisent 、TComponent、TControl、TGraphicControl、TWinControl 关系图
  7. Java事务管理之JDBC
  8. Newtonsoft.Json 序列化器的重写
  9. hdu 3389 阶梯博弈
  10. 【POJ】3270.Cow Sorting