#-swank (unless (member :child-sbcl *features*) (quit :recklessly-p t :unix-status (process-exit-code (run-program *runtime-pathname* `("--control-stack-size" "1024MB" "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options" "--eval" "(push :child-sbcl *features*)" "--script" ,(namestring *load-pathname*)) :output t :error t :input t)))) (defun read-integers () (with-open-file (stream *standard-input* :direction :input :external-format :utf-8) (loop for num = (read stream nil) while num collect num))) (defun write-result (count result) (with-open-file (stream *standard-output* :direction :output :external-format :utf-8) (format stream "~d~%" count) (loop for x in result do (format stream "~d " x)) (format stream "~%"))) (defun main () (let* ((data (read-integers)) (N (first data)) (S (second data)) (P (subseq data 2 (+ 2 N))) (indexed-P (loop for i from 0 below N collect (cons (nth i P) (1+ i)))) (sorted-P (sort indexed-P #'< :key #'car)) (result '())) (loop for i from 0 below N for (value . index) = (nth i sorted-P) for left-diff = (if (> i 0) (- value (car (nth (1- i) sorted-P))) most-positive-fixnum) for right-diff = (if (< i (1- N)) (- (car (nth (1+ i) sorted-P)) value) most-positive-fixnum) for near = (min left-diff right-diff) when (> near S) do (push index result)) (setf result (sort result #'<)) (write-result (length result) result))) (main)