(defconstant +inf+ 987654321987654321) (defun main (&rest argv) (declare (ignorable argv)) (let* ((*read-default-float-format* 'double-float) (n (read)) (p (read)) (dp1 (make-array 15015 :element-type 'integer :initial-element +inf+))) (setf (aref dp1 0) 0) (dotimes (_ n) (let* ((a (read)) (b (read)) (c (read)) (dp2 (make-array 15015 :element-type 'integer :initial-element +inf+))) (loop for j to (* 3 n) do (when (>= j 0) (setf (aref dp2 j) (min (aref dp2 j) (+ a (aref dp1 j))))) (when (>= j 1) (setf (aref dp2 j) (min (aref dp2 j) (+ b (aref dp1 (- j 1)))))) (when (>= j 2) (setf (aref dp2 j) (min (aref dp2 j) (+ c (aref dp1 (- j 2)))))) (when (>= j 3) (setf (aref dp2 j) (min (aref dp2 j) (+ 1 (aref dp1 (- j 3))))))) (replace dp1 dp2))) (format t "~f~%" (/ (float (aref dp1 p) 0d0) (float n 0d0))))) (main)