(defun put-all-p (M An)
(loop for a in An
sum a into S
always (<= S M)))
;; (put-all-p 15 '(3 1 4 1 5)) ;=> T
(defun print-yesno (c)
(declare (type boolean c))
(princ (if c "Yes""No")))
(defun main ()
(let* ((N (read))
(M (read))
(An (loop repeat N collect (read))))
(print-yesno (put-all-p M An))))
#-swank(main)Code language:Lisp(lisp)
(defun missing-list (N Am)
(let* ((ht (make-hash-table)))
(loop for a in Am
do (setf (gethash a ht) t))
(loop for i from 1 to N
when (null (gethash i ht))
collect i)))
;; (missing-list 10 '(3 9 2)) ;=> (1 4 5 6 7 8 10)
(defun main ()
(let* ((N (read))
(M (read))
(Am (loop repeat M
collect (read)))
(Xc (missing-list N Am)))
(princ (length Xc))
(terpri)
(loop for x in Xc
do (princ x)
(princ #\space))))
#-swank(main)Code language:Lisp(lisp)