#-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 fast-read-lines () (with-open-file (stream *standard-input* :direction :input :element-type '(unsigned-byte 8) :external-format :utf-8) (let ((content (make-array 1024 :element-type 'character :adjustable t :fill-pointer 0))) (loop for line = (read-line stream nil) while line do (vector-push-extend line content) (vector-push-extend #\Newline content)) (coerce content 'string)))) (defun fast-write-lines (lines) (with-open-file (stream *standard-output* :direction :output :element-type '(unsigned-byte 8) :external-format :utf-8) (loop for line in lines do (write-string line stream) (write-char #\Newline stream)))) (defun main () (let* ((input (fast-read-lines)) (input-lines (split-sequence #\Newline input)) (N (parse-integer (first input-lines))) (S (parse-integer (second input-lines))) (P (mapcar #'parse-integer (subseq input-lines 2 (1+ N)))) (indexed-P (mapcar #'(lambda (x i) (list x (1+ i))) P (loop for i from 0 below N collect i))) (sorted-P (sort indexed-P #'< :key #'first)) (result '())) (loop for i from 0 below N for (value index) = (nth i sorted-P) for left-diff = (if (> i 0) (- value (first (nth (1- i) sorted-P))) most-positive-fixnum) for right-diff = (if (< i (1- N)) (- (first (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 #'<)) (fast-write-lines (list (write-to-string (length result)) (map 'string #'write-to-string result))))) (main)