SHARE
TWEET

codeforce - puzzle

jakaria_hossain May 26th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int n,m;
  6.     scanf("%d %d",&n,&m);
  7.     int ara[m+1];
  8.     for(int i=0;i<m;i++)
  9.     {
  10.         scanf("%d",&ara[i]);
  11.     }
  12.     sort(ara,ara+m);
  13.     int ans=1005;
  14.     for(int i=0;i<=m-n;i++)
  15.     {
  16.         ans=min(ans,(ara[n+i-1]-ara[i]));
  17.     }
  18.     printf("%d\n",ans);
  19.     return 0;
  20. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top