0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ABC085C - Otoshidama

Posted at

問題

スクリーンショット 2019-11-29 21.59.08.png

回答

N,Y = gets.chomp.split.map(&:to_i)

x = -1
y = -1
z = -1

N.step( 0, -1 ) do |i|
  if 10000 * i > Y
    next
  else
    ( N - i ).step( 0, -1 ) do |j|
      if 10000 * i + 5000 * j + 1000 * ( N - i - j ) == Y
        x = i
        y = j
        z = N - i - j
        break
      end
    end
    if x != -1 || y != -1 || z != -1
      break
    end
  end
end

printf( '%d %d %d', x, y, z )

結果

スクリーンショット 2019-11-29 21.38.44.png

感想

5000円、10000円と1000円の差分である4000円と9000円で割り切れるかで確認する方法があって処理は早かったけど、流石にコード読むのが難しくなるしなあ・・・

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?