Last active
March 21, 2018 15:11
-
-
Save hamuhei1412/6f5d5a9a0ff9b05b210e4d5662a899fe to your computer and use it in GitHub Desktop.
ABC085C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Y,N = gets.split.map(&:to_i) #入力 | |
a = 0 #一万円の枚数 | |
while a * 10000 <= N | |
b = 0 #5000円の枚数 | |
while b * 5000 + a * 10000 <= N | |
c = (N - (a * 10000 + b * 5000)) / 1000 #1万円の枚数と5000円の枚数が決まれば、考えられる千円札の枚数は一意に決まる。 | |
if(a+b+c==Y&&a*10000+b*5000+c*1000==N) #枚数がYかつ合計金額がNなら出力して終了 | |
puts "#{a} #{b} #{c}" | |
exit | |
end | |
b += 1 | |
end | |
a += 1 | |
end | |
puts "-1 -1 -1" #ここまでプログラムが動いてるってことは当てはまらなかったってこと |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment