SPOJ Problem:- AMR10G - Christmas Play Solution
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 //NAME:- ANUHAR TRIPATHI //COLLEGE:- JAYPEE UNIVERSITY OF ENGINEERING & TECHNOLOGY, GUNA //EMAIL:- anuhartripathi15@gmail.com //SPOJ Problem:- AMR10G - Christmas Play # include < bits / stdc ++ .h > # define ll long long using namespace std; int main () { ll t; cin >> t; while (t -- ) { ll n,k; cin >> n >> k; ll h[n],i,j,mi = LONG_MAX; for (i = 0 ;i < n;i ++ ) cin >> h[i]; sort(h,h + n); j = 0 ; for (i = k - 1 ;i < n;i ++ ) { if (mi > h[i] - h[j]) mi = h[i] - h[j]; ++ j; } cout << mi << " \n " ; } return 0 ; }