Link:

Codeforces #196 传送门

 

A:

枚举

#include <bits/stdc++.h>

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int,int> P;
const int MAXN=1e5+10;
int n,m,dat[MAXN],res=1<<30;

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++) scanf("%d",&dat[i]);
    sort(dat+1,dat+m+1);
    for(int i=1;i<=m-n+1;i++)
        res=min(res,dat[i+n-1]-dat[i]);
    printf("%d",res);
    return 0;
}
Problem A

相关文章: