結果

問題 No.156 キャンディー・ボックス
ユーザー maimai8
提出日時 2020-08-18 14:35:34
言語 OCaml
(5.2.1)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 432 bytes
コンパイル時間 508 ms
コンパイル使用メモリ 21,320 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-09 02:00:48
合計ジャッジ時間 1,394 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

let () =
  Scanf.scanf "%d %d\n" @@ fun n m ->
  let arr = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun d -> d in
  let _ = Array.fast_sort compare arr in
  let ans, flag, sum = ref 0, ref true, ref 0 in
  while !flag do
    if !sum + arr.(!ans) < m then (sum := !sum + arr.(!ans); ans := !ans + 1)
    else if !sum + arr.(!ans) = m then (ans := !ans + 1; flag := false)
    else flag := false
  done; Printf.printf "%d\n" !ans
0