結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー nebukuro09nebukuro09
提出日時 2017-04-22 10:46:51
言語 D
(dmd 2.107.1)
結果
WA  
実行時間 -
コード長 1,222 bytes
コンパイル時間 1,530 ms
コンパイル使用メモリ 166,256 KB
実行使用メモリ 13,656 KB
最終ジャッジ日時 2023-09-03 12:57:33
合計ジャッジ時間 12,152 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 103 ms
7,208 KB
testcase_08 WA -
testcase_09 AC 1,166 ms
11,532 KB
testcase_10 AC 1,067 ms
11,496 KB
testcase_11 AC 889 ms
11,492 KB
testcase_12 AC 1,163 ms
11,528 KB
testcase_13 AC 1,066 ms
11,604 KB
testcase_14 AC 1,089 ms
11,600 KB
testcase_15 AC 1,082 ms
11,504 KB
testcase_16 AC 1,026 ms
11,544 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;


void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto a0 = readln.chomp.to!int;
    auto A = (N-1).iota.map!(_ => readln.chomp.to!int).array;
    A.sort();

    bool ok(int m) {
        int x = a0 + A[m];
        int cnt = 0;
        auto rbt = new RedBlackTree!(int, "a < b", true)();
        foreach (i; 0..N-1) if (i != m) rbt.insert(A[i]);
        
        foreach (i; 0..N-1) {
            if (i == m) continue;
            if (rbt.equalRange(A[i]).empty) continue;

            rbt.removeKey(A[i]);
            auto ub = rbt.upperBound(x - A[i]);
            if (ub.empty) continue;
            auto y = ub.front;
            rbt.removeKey(y);
            cnt += 1;
        }

        return cnt < M;
    }

    if (!ok(N-2)) {
        writeln(-1);
        return;
    }
    
    int hi = N-2;
    int lo = 0;
    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        if (ok(mid)) hi = mid;
        else lo = mid;
    }

    writeln( ok(hi) ? A[hi] : A[lo]);
}
0