301783: CF337A. Puzzles

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Puzzles

题意翻译

## 题目大意: 期末快要到了,Manana老师又将要和一个班级道别了。她决定为她的n个学生准备道别礼物——给每个人一个披萨。 商店的助理告诉老师:他们只有m个披萨,m个披萨可能大小不一样。 老师不希望让某个同学很伤心,于是引入定义A是老师买的披萨里最大的,B是最小的。她希望A-B的值越小越好。求最小的A-B值

题目描述

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 $ f_{1} $ pieces, the second one consists of $ f_{2} $ 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 $ .

输入输出格式

输入格式


The first line contains space-separated integers $ n $ and $ m $ ( $ 2<=n<=m<=50 $ ). The second line contains $ m $ space-separated integers $ f_{1},f_{2},...,f_{m} $ ( $ 4<=f_{i}<=1000 $ ) — the quantities of pieces in the puzzles sold in the shop.

输出格式


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

输入输出样例

输入样例 #1

4 6
10 12 10 7 5 22

输出样例 #1

5

说明

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.

Input

题意翻译

## 题目大意: 期末快要到了,Manana老师又将要和一个班级道别了。她决定为她的n个学生准备道别礼物——给每个人一个披萨。 商店的助理告诉老师:他们只有m个披萨,m个披萨可能大小不一样。 老师不希望让某个同学很伤心,于是引入定义A是老师买的披萨里最大的,B是最小的。她希望A-B的值越小越好。求最小的A-B值

加入题单

上一题 下一题 算法标签: