結果

問題 No.5 数字のブロック
ユーザー vjudge1
提出日時 2025-09-04 16:56:45
言語 Crystal
(1.14.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 341 bytes
コンパイル時間 18,173 ms
コンパイル使用メモリ 310,060 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-09-04 16:57:05
合計ジャッジ時間 13,683 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

# Read first number (k)
k = gets.not_nil!.to_i

# Read second number (n)
n = gets.not_nil!.to_i

# Read the array from third line
w = gets.not_nil!.split.map(&.to_i)

# Sort the array
w.sort!

# Iterate through the sorted list
result = n
w.each_with_index do |value, i|
  k -= value
  if k < 0
    result = i
    break
  end
end

puts result
0