結果

問題 No.2217 Suffix+
ユーザー simansiman
提出日時 2023-02-18 11:23:30
言語 Ruby
(3.3.0)
結果
AC  
実行時間 763 ms / 2,000 ms
コード長 444 bytes
コンパイル時間 536 ms
コンパイル使用メモリ 11,180 KB
実行使用メモリ 22,724 KB
最終ジャッジ日時 2023-09-27 05:02:12
合計ジャッジ時間 12,159 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
15,308 KB
testcase_01 AC 71 ms
15,360 KB
testcase_02 AC 70 ms
15,264 KB
testcase_03 AC 72 ms
15,336 KB
testcase_04 AC 71 ms
15,080 KB
testcase_05 AC 71 ms
15,040 KB
testcase_06 AC 79 ms
15,032 KB
testcase_07 AC 70 ms
15,300 KB
testcase_08 AC 75 ms
15,152 KB
testcase_09 AC 74 ms
15,132 KB
testcase_10 AC 71 ms
15,096 KB
testcase_11 AC 72 ms
15,216 KB
testcase_12 AC 70 ms
15,172 KB
testcase_13 AC 72 ms
15,184 KB
testcase_14 AC 138 ms
16,760 KB
testcase_15 AC 134 ms
16,664 KB
testcase_16 AC 174 ms
18,908 KB
testcase_17 AC 162 ms
17,568 KB
testcase_18 AC 143 ms
16,996 KB
testcase_19 AC 348 ms
20,448 KB
testcase_20 AC 286 ms
19,688 KB
testcase_21 AC 118 ms
15,620 KB
testcase_22 AC 350 ms
20,240 KB
testcase_23 AC 302 ms
18,964 KB
testcase_24 AC 427 ms
22,384 KB
testcase_25 AC 460 ms
22,396 KB
testcase_26 AC 394 ms
22,508 KB
testcase_27 AC 387 ms
22,560 KB
testcase_28 AC 389 ms
22,628 KB
testcase_29 AC 756 ms
22,396 KB
testcase_30 AC 750 ms
22,492 KB
testcase_31 AC 745 ms
22,468 KB
testcase_32 AC 763 ms
22,724 KB
testcase_33 AC 742 ms
22,584 KB
testcase_34 AC 296 ms
22,596 KB
testcase_35 AC 74 ms
15,032 KB
testcase_36 AC 724 ms
22,512 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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

ok = 0
ng = A.max + K * N + 1

def f(x)
  k = K
  sum = 0

  A.each.with_index(1) do |a, i|
    a += sum

    if a < x
      diff = x - a
      op_cnt = (diff + i - 1) / i
      k -= op_cnt
      sum += i * op_cnt
    end

    if k < 0
      return false
    end
  end

  true
end

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

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

puts ok
0