結果

問題 No.5 数字のブロック
コンテスト
ユーザー vjudge1
提出日時 2025-09-04 16:56:45
言語 Crystal
(1.19.1)
コンパイル:
crystal build -Donline_judge -o a.out --release --no-debug _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 5,000 ms
+ 508µs
コード長 341 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 8,327 ms
コンパイル使用メモリ 336,412 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-07-14 14:01:31
合計ジャッジ時間 9,972 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# 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