Editorial-CFRS01

problem link::`Books in Drawer
Difficulty:: medium
setter:: @sanjeev2001
Code::

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        int mn=INT_MAX,l=-1,r=-1;
        for(int i=0;i+m-1<n;i++)
        {
            int diff=a[i+m-1]-a[i];
            if(diff<mn)
            {
                mn=diff;
                l=i;
                r=i+m-1;
            }
        }
        for(int i=l;i<=r;i++)
        {
            cout<<a[i]<<" ";
        }
        cout<<endl;
    }
}

`