結果

問題 No.37 遊園地のアトラクション
ユーザー らっしー(raccy)
提出日時 2015-06-15 23:19:18
言語 Ruby
(3.4.1)
結果
RE  
実行時間 -
コード長 688 bytes
コンパイル時間 84 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,544 KB
最終ジャッジ日時 2024-07-06 21:09:01
合計ジャッジ時間 3,237 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 4
other RE * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:2: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

t = gets.to_i
n = gets.to_i
$c_list = gets.split.map(&:to_i)
$v_list = gets.split.map(&:to_i)

$max_manzoku = 0

def manzoku(kore)
  man = 0
  kore.each_with_index do |count, i|
    m = $v_list[i]
    count.times do
      man += m
      m /= 2
    end
  end
  return man
end

def noru_ato(nokori, ima, kore)
  if ima == n - 1
    kore << nokori / $c_list[ima]
    $max_manzoku = [manzoku(kore), $max_manzoku].max
  else
    count = 0
    loop do
      next_nokori = nokori - count * $c_list[ima]
      if next_nokori <= 0
        noru_ato(next_nokori, ima + 1, kore + [count])
        count += 1
      else
        break
      end
    end
  end
end

noru_ato(t, 0, [])

puts $max_manzoku
0