結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー simansiman
提出日時 2022-05-08 16:36:20
言語 Ruby
(3.3.0)
結果
AC  
実行時間 274 ms / 3,000 ms
コード長 651 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 11,344 KB
実行使用メモリ 18,124 KB
最終ジャッジ日時 2023-09-22 13:16:28
合計ジャッジ時間 5,313 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
15,128 KB
testcase_01 AC 77 ms
15,252 KB
testcase_02 AC 78 ms
15,248 KB
testcase_03 AC 79 ms
15,344 KB
testcase_04 AC 79 ms
15,272 KB
testcase_05 AC 78 ms
15,284 KB
testcase_06 AC 78 ms
15,076 KB
testcase_07 AC 161 ms
17,896 KB
testcase_08 AC 165 ms
18,096 KB
testcase_09 AC 274 ms
17,836 KB
testcase_10 AC 253 ms
17,744 KB
testcase_11 AC 233 ms
17,824 KB
testcase_12 AC 266 ms
17,960 KB
testcase_13 AC 244 ms
17,908 KB
testcase_14 AC 239 ms
17,904 KB
testcase_15 AC 244 ms
17,944 KB
testcase_16 AC 249 ms
18,124 KB
testcase_17 AC 78 ms
15,300 KB
testcase_18 AC 79 ms
15,288 KB
testcase_19 AC 78 ms
15,280 KB
testcase_20 AC 78 ms
15,120 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:36: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

N, M = gets.split.map(&:to_i)
A = N.times.map { gets.to_i }
B = A[1..-1].sort.reverse

def f(idx)
  x = A[0] + B[idx]
  left = 0
  right = B.size - 1

  cnt = 0

  while left < right
    if left == idx
      left += 1
      next
    elsif right == idx
      right -= 1
      next
    end

    v = B[left] + B[right]

    if v <= x
      right -= 1
    else
      cnt += 1
      left += 1
      right -= 1
    end
  end

  cnt < M
end

if not f(0)
  puts -1
  exit
end

if f(B.size - 1)
  puts B.last
  exit
end

ok = 0
ng = B.size - 1

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

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

puts B[ok]
0