結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー TANIGUCHI Kousuke
提出日時 2017-06-27 18:20:21
言語 Ruby
(3.4.1)
結果
AC  
実行時間 318 ms / 3,000 ms
コード長 640 bytes
コンパイル時間 38 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 14,080 KB
最終ジャッジ日時 2024-10-04 11:40:13
合計ジャッジ時間 4,442 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:33: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

def rank(score, pair, players)
    big = players.size - 1
    count = 0
    players.each_index do |small|
        break if small >= big
        
        if big == pair 
            big -= 1
            redo
        elsif small == pair
            next
        end
        
        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 = (0 .. n - 2).bsearch do |i|
    rank(K + N[i], i, N) < M
end

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



0