(defun main (&rest argv) (declare (ignorable argv)) (let* ((*read-default-float-format* 'double-float) (dp1 (make-array (ash 1 10) :initial-element nil)) (dp2 (make-array (ash 1 10) :initial-element nil)) (n (read)) (a (make-array n :element-type 'integer))) (dotimes (i n) (setf (aref a i) (read))) (let* ((m (read)) (b (make-array m :element-type 'integer))) (dotimes (i m) (setf (aref b i) (read))) (sort b #'>) (setf (aref dp1 0) t) (dotimes (i m) (dotimes (j (ash 1 n)) (let ((c 0)) (dotimes (k n) (unless (evenp (ash j (- k))) (incf c (aref a k)))) (unless (> c (aref b i)) (loop for k from (1- (ash 1 n)) downto 0 do (setf (aref dp2 (logior j k)) (or (aref dp2 (logior j k)) (aref dp1 k))))))) (loop for k from (1- (ash 1 n)) downto 0 do (setf (aref dp1 k) (aref dp2 k))) (when (aref dp1 (1- (ash 1 n))) (format t "~d~%" (1+ i)) (return-from main))) (format t "-1~%")))) (main)