Created
December 31, 2018 06:10
-
-
Save ateruimashin/fd31dc210fc943de2e681486fb7e28c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
#include <climits> | |
using namespace std; | |
int main(int argc, char const *argv[]) { | |
int n,k; | |
cin>>n>>k; | |
vector<int> v(n); | |
for(int i=0;i<n;i++){ | |
cin>>v[i]; | |
} | |
sort(v.begin(),v.end()); | |
int min=INT_MAX; | |
for(int i=0;i+k-1<n;i++){ | |
int tmp=v[i+k-1]-v[i]; | |
if(tmp<min) min=tmp; | |
} | |
cout<<min<<endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment