(defun main (&rest argv) (declare (ignorable argv)) (let* ((tm (read)) (n (read)) (c (make-array n)) (v (make-array n)) (dp (make-array (1+ tm) :element-type 'integer :initial-element -1)) (res 0)) (dotimes (i n) (setf (aref c i) (read))) (dotimes (i n) (setf (aref v i) (read))) (setf (aref dp 0) 0) (dotimes (i n) (loop for j from (1- tm) downto 0 unless (= -1 (aref dp j)) do (let ((point (aref v i)) (a 0) (k 1)) (loop while (plusp point) do (progn (let ((now (+ j (* k (aref c i))))) (when (<= now tm) (incf a point) (if (< (aref dp now) (+ (aref dp j) a)) (setf (aref dp now) (+ (aref dp j) a)) (return)))) (incf k) (setf point (floor point 2))))))) (loop for i from tm downto 0 do (setq res (max res (aref dp i)))) (format t "~d~%" res))) (main)