結果

問題 No.5 数字のブロック
ユーザー pekempey
提出日時 2016-06-23 09:20:55
言語 Scheme
(Gauche-0.9.15)
結果
AC  
実行時間 56 ms / 5,000 ms
コード長 575 bytes
コンパイル時間 211 ms
コンパイル使用メモリ 6,816 KB
実行使用メモリ 18,944 KB
最終ジャッジ日時 2024-11-18 08:42:12
合計ジャッジ時間 2,153 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

(define (iota n . args)
  (let ((start (if (pair? args) (car args) 0))
        (step  (if (and (pair? args) (pair? (cdr args))) (cadr args) 1)))
    (let loop ((m n) (last (+ start (* step (- n 1)))) (a '()))
      (if (zero? m)
          a
	  (loop (- m 1) (- last step) (cons last a))))))

(write (let* ((L (read)) (N (read)) (W (sort (map (lambda (x) (read)) (iota N)) <)))
	 (let loop((a W) (sum 0) (res 0))
	   (if (null? a)
	       res
	       (let ((next-sum (+ sum (car a))))
		 (if (<= next-sum L)
		     (loop (cdr a) next-sum (+ res 1))
		     res))))))
(newline)
0