結果

問題 No.1046 Fruits Rush
ユーザー xsd
提出日時 2020-06-15 20:36:45
言語 OCaml
(5.2.1)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 290 bytes
コンパイル時間 317 ms
コンパイル使用メモリ 21,448 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-09 01:18:12
合計ジャッジ時間 984 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

Scanf.scanf "%d %d" (fun n k ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    Array.sort (fun a b -> compare b a) a;
    let rec loop i sum =
        if i = k || a.(i) < 0 then sum else loop (i + 1) (sum + a.(i))
    in
    loop 1 a.(0) |> Printf.printf "%d\n"
)
0