結果

問題 No.156 キャンディー・ボックス
コンテスト
ユーザー Common Lisp
提出日時 2024-10-08 12:44:15
言語 Common Lisp
(sbcl 2.6.3)
コンパイル:
sbclc _filename_
実行:
sbcl --script Main.fasl
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 826 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 66 ms
コンパイル使用メモリ 29,440 KB
実行使用メモリ 22,400 KB
最終ジャッジ日時 2026-04-24 22:49:02
合計ジャッジ時間 2,220 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge4_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 24 APR 2026 10:48:58 PM):

; wrote /home/judge/data/code/Main.fasl
; compilation finished in 0:00:00.004

ソースコード

diff #
raw source code

; 与えられた Ci を昇順ソートして小さいものから足し続ける
; m を超えたときのインデックスを出力する

; 【解1】for ループ
(defun main ()
  (let* ((n (read))
         (m (read))
         (xs (sort (loop repeat n collect (read)) #'<)))
    (loop for i below n
          for s = (car xs) then (+ s (nth i xs))
          until (> s m)
          finally (princ i))
    (terpri)))
(main)

; 【解2】再帰
; (defun scanl (fn init xs)
;   (if (null xs)
;       (list init)
;     (cons init (scanl fn (funcall fn (car xs) init) (cdr xs)))))
; (defun main ()
;   (let* ((n (read))
;          (m (read))
;          (xs (sort (loop repeat n collect (read)) #'<)))
;     (princ (length (remove-if #'plusp (map 'list (lambda (x) (- x m)) (scanl #'+ (car xs) xs)))))
;     (terpri)))
; (main)
0