-
Notifications
You must be signed in to change notification settings - Fork 1
/
AMR10G.cpp
49 lines (42 loc) · 939 Bytes
/
AMR10G.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
49
#include <iostream>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <algorithm>
#include <limits.h>
#include <cstring>
#include <cmath>
#define ll long
#define get(a) scanf("%ld", &a)
#define rep(n) for( ll i = 0; i < n; i++ )
#define repVector(v) for(vector<ll>::iterator it = v.begin(); it != v.end(); it++ )
#define all(c) c.begin(), c.end()
#define repu(a,n) for( ll i = a; i < n; i++ )
#define max(a,b) a > b ? a : b
#define pb push_back
using namespace std;
int main() {
ll t;
get(t);
while(t--) {
ll n, k;
get(n); get(k);
vector<ll> v;
rep(n) {
ll x;
get(x);
v.pb(x);
}
sort( all(v) );
ll min = LONG_MAX;
rep(n-k+1) {
ll x = v[i+k-1] - v[i];
if( min > x )
min = x;
}
printf("%ld\n", min);
}
}