結果

問題 No.156 キャンディー・ボックス
ユーザー ichibanshibori
提出日時 2017-03-18 19:31:02
言語 OCaml
(5.2.1)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 501 bytes
コンパイル時間 322 ms
コンパイル使用メモリ 21,572 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-08 23:58:32
合計ジャッジ時間 1,559 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

let solve m c_lst =
  let rec solve' rest lst result =
    match lst with
    | [] -> result
    | x::xs ->
      if rest < x then
        result
      else
        solve' (rest - x) xs (result + 1)
  in
  solve' m c_lst 0

let () =
  let m =
    read_line ()
    |> (fun l -> Scanf.sscanf l "%d %d" (fun _ m -> m))
  and c_lst =
    read_line ()
    |> Str.split (Str.regexp_string " ")
    |> List.map int_of_string
    |> List.sort compare
  in
  solve m c_lst
  |> string_of_int
  |> print_endline
0