結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー cympfhcympfh
提出日時 2017-05-21 17:48:47
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 664 bytes
コンパイル時間 509 ms
コンパイル使用メモリ 11,840 KB
実行使用メモリ 34,688 KB
最終ジャッジ日時 2023-10-19 12:04:15
合計ジャッジ時間 8,569 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
16,056 KB
testcase_01 AC 82 ms
16,056 KB
testcase_02 AC 86 ms
16,056 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 81 ms
16,056 KB
testcase_06 RE -
testcase_07 AC 153 ms
18,816 KB
testcase_08 AC 215 ms
18,816 KB
testcase_09 AC 149 ms
18,356 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 85 ms
16,056 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:40: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Main.rb:20: 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)
  t = []
  s = []
  as.each_with_index do |b, idx|
    next if idx == ignore_index
    s << b
    if s.size == 2
      t << s.inject(:+)
      s = []
    end
    break if t.size == m
  end
  a >= t[-1]
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
    100.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