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);
}

Codeforces Round #196 (Div. 2) A. Puzzles 水题的更多相关文章

  1. Codeforces Round #185 (Div. 2) B. Archer 水题

    B. Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/problem/B D ...

  2. Codeforces Round #360 (Div. 2) A. Opponents 水题

    A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...

  3. Codeforces Round #190 (Div. 2) 水果俩水题

    后天考试,今天做题,我真佩服自己... 这次又只A俩水题... orz各路神犇... 话说这次模拟题挺多... 半个多小时把前面俩水题做完,然后卡C,和往常一样,题目看懂做不出来... A: 算是模拟 ...

  4. Codeforces Round #256 (Div. 2/A)/Codeforces448A_Rewards(水题)解题报告

    对于这道水题本人觉得应该应用贪心算法来解这道题: 下面就贴出本人的代码吧: #include<cstdio> #include<iostream> using namespac ...

  5. Codeforces Round #340 (Div. 2) B. Chocolate 水题

    B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...

  6. Codeforces Round #340 (Div. 2) A. Elephant 水题

    A. Elephant 题目连接: http://www.codeforces.com/contest/617/problem/A Descriptionww.co An elephant decid ...

  7. Codeforces Round #340 (Div. 2) D. Polyline 水题

    D. Polyline 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co There are three p ...

  8. Codeforces Round #338 (Div. 2) A. Bulbs 水题

    A. Bulbs 题目连接: http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...

  9. Codeforces Round #282 (Div. 1) A. Treasure 水题

    A. Treasure Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/494/problem/A ...

随机推荐

  1. leetcode刷刷刷

    1.链表节点的插入排序(写了个插入排序,但是报段错误,自己编译器里能运行) #include <iostream> #include <stdlib.h> #include & ...

  2. 下一代Android打包工具,100个渠道包只需要10秒钟 https://github.com/mcxiaoke

    https://github.com/mcxiaoke/packer-ng-plugin https://github.com/Meituan-Dianping/walle https://githu ...

  3. 常用sql 全记录(添加中)

    -- 数据库SQL总结中........... --SQL分类: (CREATE,ALTER,DROP,DECLARE) ---DDL—数据定义语言(SELECT,DELETE,UPDATE,INSE ...

  4. Oracle学习笔记:wm_concat函数合并字段

    在Oracle中使用wm_concat(column)可以实现字段的分组合并,逗号分隔. 例如,现有表temp_cwh_test: -- 创建临时表 create table temp_cwh_tes ...

  5. Mac OS 下安装mysqlclient报“mysql_config not found”的解决

    如问题所示,应该是你没有将mysql_config所在文件夹加入系统的PATH路径,解决方案下: 1.第一步找到你的mysql_config所在位置 1.1. 如果是直接安装mysql,所在位置应该是 ...

  6. php单双引号嵌套解决方案

    代码如下: <?php $path = "./"; function show_files($path){ //下面是单双引号嵌套解决方案 //echo "< ...

  7. C# 在RichTextBox根据内容自动调整高度

    private void richTextBox1_ContentsResized(object sender, ContentsResizedEventArgs e)   {   richTextB ...

  8. AndroidStudio3.0到3.1遇到的坑

    原文:https://blog.csdn.net/qq_36676433/article/details/80361064 本以为3.0到3.1仅仅是界面的优化,万万没想到的是这个坑比起2.0到3.0 ...

  9. springboot 1.5.X junit测试

    import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; impo ...

  10. swftools中的pdf2swf转换Error overflow ID 65535 解决办法

    近几日因为项目需要在线转换pdf到swf实现电子期刊阅读,用到了这个工具,版本是:swftools-0.9.2.tar.gz 当然也遇到了很头疼的问题,那就是在转换pdf中色彩图形比较复杂的页时会抛出 ...