結果
| 問題 |
No.507 ゲーム大会(チーム決め)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-05-21 18:00:27 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 347 ms / 3,000 ms |
| コード長 | 856 bytes |
| コンパイル時間 | 149 ms |
| コンパイル使用メモリ | 7,424 KB |
| 実行使用メモリ | 14,720 KB |
| 最終ジャッジ日時 | 2024-09-19 08:09:37 |
| 合計ジャッジ時間 | 4,606 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 19 |
コンパイルメッセージ
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
ソースコード
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