結果

問題 No.507 ゲーム大会(チーム決め)
コンテスト
ユーザー TANIGUCHI Kousuke
提出日時 2017-06-26 19:23:22
言語 Ruby
(4.0.2)
コンパイル:
ruby -w -c _filename_
実行:
ruby _filename_
結果
WA  
実行時間 -
コード長 627 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 53 ms
コンパイル使用メモリ 9,216 KB
実行使用メモリ 16,904 KB
最終ジャッジ日時 2026-04-20 06:23:22
合計ジャッジ時間 3,228 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other AC * 1 WA * 18
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:32: warning: ambiguous first argument; put parentheses or a space even after `-` operator
Syntax OK

ソースコード

diff #
raw source code

def prize(score, pair, players)
    big = players.size - 1
    count = 0
    players.each_index do |small|
        break if small >= big
        
        next if big == pair || small == pair
        
        oscore = players[big] + players[small]
        if oscore > score
            count += 1
            big -= 1
        end
    end
    count
end

n, M = gets.split.map(&:to_i)
N = n.times.map{ gets.to_i }
K = N.shift
N.sort!

min_pair = N.bsearch_index do |pair|
    if pair >= N.size
        false
    else
        prize(N[pair] + K, pair, N) > M
    end
end

if min_pair.nil?
    puts -1
else
    puts N[min_pair]
end

0