-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path337A.cpp
48 lines (34 loc) · 829 Bytes
/
337A.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//<<<<<<<<<<<<<Tushars_07>>>>>>>>>>>>>>>>
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define ll long long
#define no cout<<"NO \n";
#define yes cout<<"YES \n";
#define test lli trtyuio ; cin>>trtyuio; while(trtyuio--)
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a , b ;
cin >> a >> b ;
vector <int> arr ,arr2 ;
for(int i = 0 ; i<b ; i++){
int n ;
cin >> n ;
arr.push_back(n);
}
sort(arr.begin(),arr.end());
int i = 0 ;
while(i+a-1<b){
arr2.push_back(arr[i+a-1]-arr[i]);
i++;
}
int min = INT_MAX;
for(int i = 0 ; i<arr2.size() ; i++){
if(arr2[i]<min)
min=arr2[i];
}
cout<<min;
return 0;
}
//<<<<<<<<<<Tushars_07>>>>>>>>>>>>>>>>