Skip to content

Instantly share code, notes, and snippets.

@hamuhei1412
Last active March 21, 2018 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamuhei1412/6f5d5a9a0ff9b05b210e4d5662a899fe to your computer and use it in GitHub Desktop.
Save hamuhei1412/6f5d5a9a0ff9b05b210e4d5662a899fe to your computer and use it in GitHub Desktop.
ABC085C
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