結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2017-06-27 18:20:21
言語 Ruby
(3.3.0)
結果
AC  
実行時間 369 ms / 3,000 ms
コード長 640 bytes
コンパイル時間 37 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 14,208 KB
最終ジャッジ日時 2024-04-15 02:46:39
合計ジャッジ時間 5,121 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
12,160 KB
testcase_01 AC 90 ms
12,288 KB
testcase_02 AC 88 ms
12,288 KB
testcase_03 AC 89 ms
12,288 KB
testcase_04 AC 90 ms
12,160 KB
testcase_05 AC 88 ms
12,160 KB
testcase_06 AC 88 ms
12,160 KB
testcase_07 AC 356 ms
13,952 KB
testcase_08 AC 287 ms
13,952 KB
testcase_09 AC 369 ms
14,208 KB
testcase_10 AC 322 ms
14,080 KB
testcase_11 AC 290 ms
14,080 KB
testcase_12 AC 365 ms
13,952 KB
testcase_13 AC 296 ms
14,080 KB
testcase_14 AC 299 ms
14,080 KB
testcase_15 AC 296 ms
13,952 KB
testcase_16 AC 294 ms
14,080 KB
testcase_17 AC 89 ms
12,160 KB
testcase_18 AC 89 ms
12,288 KB
testcase_19 AC 92 ms
12,288 KB
testcase_20 AC 89 ms
12,416 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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