(defconstant +inf+ 9876543210) (defun main (&rest argv) (declare (ignorable argv)) (let* ((n (read)) (c (read)) (v (read)) (ss (make-array v :element-type 'integer)) (tt (make-array v :element-type 'integer)) (yy (make-array v :element-type 'integer)) (mm (make-array v :element-type 'integer)) (dp (make-array (list n (1+ c)) :initial-element +inf+)) (graph (make-array n :element-type 'list :initial-element nil))) (dotimes (i v) (setf (aref ss i) (1- (read)))) (dotimes (i v) (setf (aref tt i) (1- (read)))) (dotimes (i v) (setf (aref yy i) (read))) (dotimes (i v) (setf (aref mm i) (read))) (dotimes (i v) (push (list (aref tt i) (aref yy i) (aref mm i)) (aref graph (aref ss i)))) (setf (aref dp 0 c) 0) (loop for i below (1- n) do (loop for j to c do (when (< (aref dp i j) +inf+) (dolist (pqr (aref graph i)) (let ((p (first pqr)) (q (second pqr)) (r (third pqr))) (when (>= (- j q) 0) (setf (aref dp p (- j q)) (min (aref dp p (- j q)) (+ r (aref dp i j)))))))))) (let ((res (loop for i to c minimize (aref dp (1- n) i)))) (format t "~d~%" (if (< res +inf+) res -1))))) (main)