結果

問題 No.1046 Fruits Rush
ユーザー penqenpenqen
提出日時 2020-12-16 14:27:18
言語 Elixir
(1.16.2)
結果
AC  
実行時間 600 ms / 2,000 ms
コード長 562 bytes
コンパイル時間 1,118 ms
コンパイル使用メモリ 57,088 KB
実行使用メモリ 50,676 KB
最終ジャッジ日時 2023-08-30 01:11:34
合計ジャッジ時間 12,434 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 578 ms
50,376 KB
testcase_01 AC 583 ms
50,380 KB
testcase_02 AC 573 ms
49,604 KB
testcase_03 AC 573 ms
49,788 KB
testcase_04 AC 570 ms
49,684 KB
testcase_05 AC 571 ms
49,608 KB
testcase_06 AC 572 ms
49,708 KB
testcase_07 AC 574 ms
49,580 KB
testcase_08 AC 600 ms
50,192 KB
testcase_09 AC 569 ms
49,692 KB
testcase_10 AC 573 ms
49,648 KB
testcase_11 AC 572 ms
49,796 KB
testcase_12 AC 583 ms
49,708 KB
testcase_13 AC 576 ms
50,296 KB
testcase_14 AC 571 ms
50,676 KB
testcase_15 AC 575 ms
49,636 KB
testcase_16 AC 577 ms
49,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

defmodule Main do
  
  def main do
    [n, k] = IO.read(:line) |> String.trim() |> String.split(" ") |> Enum.map(&String.to_integer/1)
    an = IO.read(:line) |> String.trim() |> String.split(" ") |> Enum.map(&String.to_integer/1)
    solve(n, k, an) |> IO.puts()
  end

  def solve(n, k, an) when 1 <= k and k <= n and n <= 100 do
    an = an |> Enum.sort(&(&1 > &2))

    an
    |> Enum.reject(&(&1 < 1))
    |> (fn
      [] ->
        [t | _] = an
        [t]
      x ->
        x
    end).()
    |> Stream.take(k)
    |> Enum.reduce(0, &(&1 + &2))
  end

end
0