CF337A.Puzzles

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 nn 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 mm puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of f1f_{1} pieces, the second one consists of f2f_{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 AA be the number of pieces in the largest puzzle that the teacher buys and BB be the number of pieces in the smallest such puzzle. She wants to choose such nn puzzles that ABA-B is minimum possible. Help the teacher and find the least possible value of ABA-B .

输入格式

The first line contains space-separated integers nn and mm ( 2<=n<=m<=502<=n<=m<=50 ). The second line contains mm space-separated integers f1,f2,...,fmf_{1},f_{2},...,f_{m} ( 4<=fi<=10004<=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.

首页