結果

問題 No.842 初詣
コンテスト
ユーザー gemmaro
提出日時 2019-11-04 08:24:21
言語 Ruby
(4.0.2)
コンパイル:
ruby -w -c _filename_
実行:
ruby _filename_
結果
WA  
実行時間 -
コード長 602 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 194 ms
コンパイル使用メモリ 8,960 KB
実行使用メモリ 14,848 KB
最終ジャッジ日時 2026-04-04 15:49:00
合計ジャッジ時間 1,947 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14 WA * 7
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #
raw source code

# coins: [int; 6] = [500, 100, 50, 10, 5, 1]
#                      0    1   2   3  4  5
$rates = [5, 2, 5, 2, 5]
$values = [500, 100, 50, 10, 5]

def normalize coins
    5.times {|i|
        coins[4 - i] += coins[5 - i] / $rates[4 - i]
        coins[5 - i] %= $rates[4 - i]
    }
    coins
end

def is_possible coins, target
    5.times {|i|
        return false if coins[i] < target / $values[i]
        target %= $values[i]
    }
    return false if coins[5] < target
    true
end

a, b, c, d, e, f, g = gets.chomp.split.map &:to_i
puts (is_possible(normalize([a, b, c, d, e, f]), g)) ? "YES" : "NO"
0