結果
| 問題 |
No.507 ゲーム大会(チーム決め)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-05-21 17:48:47 |
| 言語 | Ruby (3.4.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 664 bytes |
| コンパイル時間 | 48 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 31,616 KB |
| 最終ジャッジ日時 | 2024-09-19 08:08:50 |
| 合計ジャッジ時間 | 6,595 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 6 WA * 12 RE * 1 |
コンパイルメッセージ
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
ソースコード
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