結果

問題 No.1738 What's in the box?
ユーザー siman
提出日時 2021-11-22 18:29:15
言語 Ruby
(3.4.1)
結果
RE  
実行時間 -
コード長 337 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,544 KB
最終ジャッジ日時 2024-06-24 06:33:17
合計ジャッジ時間 9,134 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 68 RE * 2
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, M = gets.split.map(&:to_i)
W = gets.split.map(&:to_i)
gcd = W.inject(&:gcd)
S = W.sum
BW = Rational(S, M)
NW = W.map { |x| x / gcd }

def f(r)
  NW.map { |x| x * r }.sum <= M
end

ok = 1
ng = 10 ** 9

while (ok - ng).abs >= 2
  r = (ok + ng) / 2

  if f(r)
    ok = r
  else
    ng = r
  end
end

puts NW.map { |x| x * ok }.join(' ')
0