(deftype uint nil `(integer 0 ,(expt 10 9)))

;; BEGIN_INSERTED_CONTENTS
(declaim (inline %merge))
(defun %merge (l mid r source-vec dest-vec predicate)
  (loop with i = l
        with j = mid
        for idx from l
        when (= i mid)
          do (loop for j from j below r
                   for idx from idx
                   do (setf (aref dest-vec idx)
                            (aref source-vec j))
                   finally (return-from %merge t))
        when (= j r)
          do (loop for i from i below mid
                   for idx from idx
                   do (setf (aref dest-vec idx)
                            (aref source-vec i))
                   finally (return-from %merge t))
        do (if (funcall predicate (aref source-vec i) (aref source-vec j))
               (setf (aref dest-vec idx) (aref source-vec i)
                     i (1+ i))
               (setf (aref dest-vec idx) (aref source-vec j)
                     j (1+ j)))))

(declaim (inline merge-sort!))
(defun merge-sort! (vector predicate)
  (declare (vector vector)
           (function predicate))
  (let* ((len (length vector))
         (vec1 vector)
         (vec2 (make-array len :element-type 'uint)))
    (declare (dynamic-extent vec2))
    (labels ((%merge-sort (l r merge-to-vec1-p)
               (declare (uint l r))
               (if (<= (- r l) 2)
                   (if (funcall predicate (aref vec1 l) (aref vec1 (- r 1)))
                       (unless merge-to-vec1-p
                         (setf (aref vec2 l) (aref vec1 l)
                               (aref vec2 (- r 1)) (aref vec1 (- r 1))))
                       (if merge-to-vec1-p
                           (rotatef (aref vec1 l) (aref vec1 (- r 1)))
                           (setf (aref vec2 l) (aref vec1 (- r 1))
                                 (aref vec2 (- r 1)) (aref vec1 l))))
                   (let ((mid (ceiling (+ l r) 2)))
                     (%merge-sort l mid (not merge-to-vec1-p))
                     (%merge-sort mid r (not merge-to-vec1-p))
                     (if merge-to-vec1-p
                         (%merge l mid r vec2 vec1 predicate)
                         (%merge l mid r vec1 vec2 predicate))))))
      (unless (zerop len)
        (%merge-sort 0 len t))
      vector)))

(declaim (inline read-line-into))
(defun read-line-into (buf-str &optional (in *standard-input*) (terminate-char #\Newline))
  (declare (simple-base-string buf-str))
  (loop for ch of-type base-char =
           #-swank (code-char (read-byte in nil #\Newline))
           #+swank (read-char in nil #\Newline)
        for idx = 0 then (1+ idx)
        until (char= ch #\Newline)
        do (setf (aref buf-str idx) ch)
        finally (setf (aref buf-str idx) terminate-char)
                (return buf-str)))

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

;; Hauptteil
(defun main ()
  (declare (optimize (speed 3) (safety 0)))
  (let* ((n (read))
         (k (read))
         (table (make-array (list n) :element-type 'uint))
         (buf (make-string 11 :element-type 'standard-char :initial-element #\Newline)))
    (declare (uint k)
             ((simple-array uint (*)) table))
    (dotimes (idx n)
      (setf (aref table idx)
            (parse-integer (read-line-into buf *standard-input* #\Newline) :junk-allowed t)))
    (merge-sort! (the (simple-array uint (*)) table) #'<)
    (println
     (loop for begin-idx from 0
           for end-idx from (- (min k (length table)) 1) below (length table)
           minimize (- (aref table end-idx) (aref table begin-idx))))))

#-swank(main)


Measured memory_bytes: 23016