結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー cympfhcympfh
提出日時 2017-05-21 18:00:27
言語 Ruby
(3.3.0)
結果
AC  
実行時間 363 ms / 3,000 ms
コード長 856 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 11,912 KB
実行使用メモリ 18,876 KB
最終ジャッジ日時 2023-10-19 12:05:00
合計ジャッジ時間 5,086 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
16,116 KB
testcase_01 AC 88 ms
16,116 KB
testcase_02 AC 87 ms
16,116 KB
testcase_03 AC 84 ms
16,116 KB
testcase_04 AC 86 ms
16,116 KB
testcase_05 AC 82 ms
16,116 KB
testcase_06 AC 82 ms
16,116 KB
testcase_07 AC 167 ms
18,876 KB
testcase_08 AC 167 ms
18,876 KB
testcase_09 AC 359 ms
18,436 KB
testcase_10 AC 320 ms
18,436 KB
testcase_11 AC 294 ms
18,876 KB
testcase_12 AC 363 ms
18,436 KB
testcase_13 AC 294 ms
18,876 KB
testcase_14 AC 291 ms
18,876 KB
testcase_15 AC 290 ms
18,876 KB
testcase_16 AC 291 ms
18,876 KB
testcase_17 AC 89 ms
16,116 KB
testcase_18 AC 87 ms
16,116 KB
testcase_19 AC 82 ms
16,116 KB
testcase_20 AC 82 ms
16,116 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:46: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Main.rb:26: warning: assigned but unused variable - ans
Syntax OK

ソースコード

diff #

n, m = gets.chomp.split.map(&:to_i)
a = gets.to_i
as = (2..n).map { gets.to_i }.sort.reverse

def ok(a, m, as, ignore_index)
  k = 0
  left = 0
  right = as.size - 1
  left += 1 if left == ignore_index
  right -= 1 if right == ignore_index
  while left < right
    if as[left] + as[right] > a
      k += 1
      left += 1
      right -= 1
    else
      right -= 1
    end
    left += 1 if left == ignore_index
    right -= 1 if right == ignore_index
  end
  # p ['ok-check', [a,m,as,ignore_index], k, (k <= m)]
  k < m
end

ans = -1
left = 0
right = n - 2

if ok(a + as[left], m, as, left)
  if ok(a + as[right], m, as, right)
    p as[right]
  else
    # bisearch
    30.times do
      mid = (left + right) / 2
      if ok(a + as[mid], m, as, mid)
        left = mid
      else
        right = mid
      end
    end
    p as[left]
  end
else
  p -1
end

0