結果

問題 No.156 キャンディー・ボックス
コンテスト
ユーザー tanson
提出日時 2025-09-04 01:12:49
言語 Standard ML
(MLton 20241230)
コンパイル:
mlton_wrapper _filename_
実行:
./main
結果
AC  
実行時間 0 ms / 2,000 ms
+ 726µs
コード長 863 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,742 ms
コンパイル使用メモリ 704,488 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-07-14 13:55:38
合計ジャッジ時間 5,716 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

fun readInt () =
    valOf (TextIO.scanStream (Int.scan StringCvt.DEC) TextIO.stdIn)

fun quicksort [] = []
  | quicksort (h::tl) =
    let 
        val (s, b) =
            List.foldl
                (fn (x, (small, big)) =>
                    if x <= h then (x::small, big)
                    else (small, x::big))
                ([], [])
                tl
    in
        (quicksort s) @ [h] @ (quicksort b)
    end

fun takeOutCandies _ [] = 0
  | takeOutCandies numToTake (h::tl) =
    if h = numToTake then List.length tl
    else if h < numToTake then takeOutCandies (numToTake - h) tl
    else List.length (h::tl)

val () =
    let
        val n = readInt ()
        val m = readInt ()
        val c_s = List.tabulate (n, fn _ => readInt ())
        val ans = n - takeOutCandies m (quicksort c_s)
    in
        print (Int.toString ans ^ "\n")
    end
0