結果

問題 No.1808 Fullgold Alchemist
ユーザー simansiman
提出日時 2022-01-15 01:38:59
言語 Ruby
(3.3.0)
結果
AC  
実行時間 391 ms / 2,000 ms
コード長 390 bytes
コンパイル時間 213 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 26,368 KB
最終ジャッジ日時 2024-04-30 20:43:06
合計ジャッジ時間 7,775 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
12,288 KB
testcase_01 AC 75 ms
12,288 KB
testcase_02 AC 74 ms
12,160 KB
testcase_03 AC 75 ms
12,160 KB
testcase_04 AC 73 ms
12,160 KB
testcase_05 AC 138 ms
25,856 KB
testcase_06 AC 195 ms
25,344 KB
testcase_07 AC 138 ms
25,216 KB
testcase_08 AC 391 ms
26,368 KB
testcase_09 AC 246 ms
26,368 KB
testcase_10 AC 158 ms
26,240 KB
testcase_11 AC 240 ms
26,112 KB
testcase_12 AC 143 ms
25,600 KB
testcase_13 AC 323 ms
25,600 KB
testcase_14 AC 263 ms
25,600 KB
testcase_15 AC 256 ms
25,600 KB
testcase_16 AC 83 ms
12,416 KB
testcase_17 AC 74 ms
12,160 KB
testcase_18 AC 98 ms
13,952 KB
testcase_19 AC 80 ms
12,288 KB
testcase_20 AC 129 ms
14,976 KB
testcase_21 AC 91 ms
13,056 KB
testcase_22 AC 75 ms
12,160 KB
testcase_23 AC 85 ms
12,544 KB
testcase_24 AC 82 ms
12,288 KB
testcase_25 AC 77 ms
12,160 KB
testcase_26 AC 110 ms
13,696 KB
testcase_27 AC 134 ms
14,336 KB
testcase_28 AC 297 ms
24,960 KB
testcase_29 AC 155 ms
16,128 KB
testcase_30 AC 153 ms
15,744 KB
testcase_31 AC 270 ms
23,552 KB
testcase_32 AC 257 ms
19,200 KB
testcase_33 AC 302 ms
21,632 KB
testcase_34 AC 374 ms
24,576 KB
testcase_35 AC 247 ms
20,352 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, M = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)

def f(x)
  stock = 0
  cost = x * M

  A.each do |a|
    return false if (a + stock) < cost

    if cost <= a
      stock += a - cost
    else
      r = cost - a
      stock -= r
    end
  end

  true
end

ok = 0
ng = 10 ** 18

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

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

puts ok
0