結果

問題 No.5 数字のブロック
ユーザー ichibanshibori
提出日時 2016-10-01 17:14:33
言語 OCaml
(5.2.1)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 496 bytes
コンパイル時間 309 ms
コンパイル使用メモリ 19,568 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-10-08 23:49:41
合計ジャッジ時間 1,512 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

let solve l wlst =
  let rec solve' wlst sumw result =
    match wlst with
    | [] -> result
    | x::xs ->
      if (x + sumw) > l then result
      else solve' xs (sumw + x) (result + 1)
  in
  let wlst' = List.sort compare wlst in
  solve' wlst' 0 0

let () =
  let l = read_line () |> int_of_string
  and _ = read_line ()
  and wlst = read_line () |>
             Str.split (Str.regexp_string " ") |>
             List.map int_of_string
  in
  solve l wlst |> string_of_int |> print_endline
0