0
0
何冯成
中级光能
中级光能
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int a[1100000],minn=100000;
int main(){
//freopen("diff.in","r",stdin);
//freopen("diff.out","w",stdout);
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>a[i];
sort(a+1,a+n+1);
int i=1,j=n-k;
while(j<=n){
if(minn>a[j]-a[i]){
minn=a[j]-a[i];
}
i++;
j++;
}
cout<<minn;
//fclose(stdin);
//fclose(stdout);
return 0;
}
0