結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー noriocnorioc
提出日時 2017-08-19 02:48:38
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 43 ms / 3,000 ms
コード長 1,335 bytes
コンパイル時間 609 ms
コンパイル使用メモリ 98,244 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 16:00:52
合計ジャッジ時間 1,898 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 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 43 ms
4,380 KB
testcase_08 AC 41 ms
4,380 KB
testcase_09 AC 25 ms
4,380 KB
testcase_10 AC 24 ms
4,376 KB
testcase_11 AC 27 ms
4,380 KB
testcase_12 AC 25 ms
4,384 KB
testcase_13 AC 43 ms
4,380 KB
testcase_14 AC 42 ms
4,384 KB
testcase_15 AC 41 ms
4,380 KB
testcase_16 AC 42 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

bool can(int myScore, int p, int m, int[] xs) {
    int lt = 0;
    int rt = cast(int) xs.length - 1;

    int n = 0;
    while (lt < rt) {
        if (lt == p) {
            lt++;
        }
        else if (rt == p) {
            rt--;
        }
        else if (xs[lt] + xs[rt] > myScore) {
            n++;
            lt++;
            rt--;
        }
        else {
            lt++;
        }
    }
    return n < m;
}

int calc(int a0, int m, int[] xs) {
    xs.sort;

    int ans = int.max;
    int lo = 0;
    int hi = cast(int) xs.length - 1;
    while (lo <= hi) {
        int mid = (lo + hi) / 2;

        int myScore = a0 + xs[mid];
        if (can(myScore, mid, m, xs)) {
            hi = mid - 1;
            ans = min(ans, mid);
        }
        else {
            lo = mid + 1;
        }
    }
    return ans == int.max ? -1 : xs[ans];
}

void main() {
    auto nm = readints();
    int n = nm[0], m = nm[1];

    int a0 = readint();
    int[] xs;
    for (int i = 0; i < n - 1; i++) {
        xs ~= readint();
    }
    writeln(calc(a0, m, xs));
}
0