結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-04-22 00:31:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 3,000 ms
コード長 865 bytes
コンパイル時間 1,575 ms
コンパイル使用メモリ 167,312 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-28 11:30:43
合計ジャッジ時間 2,817 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)



int N, M, A[101010];
//-----------------------------------------------------------------------------------
bool chk(int idx) {
    int P = A[0] + A[idx];
    int cnt = 0;
    int L = 1, R = N - 1;
    while (L < R) {
        if (L == idx) L++;
        else if (R == idx) R--;
        else if (A[L] + A[R] <= P) L++;
        else {
            cnt++;
            L++; R--;
        }
    }

    return cnt < M;
}
//-----------------------------------------------------------------------------------
int main() {
    cin >> N >> M;
    rep(i, 0, N) scanf("%d", &A[i]);
    A[N] = -1;

    sort(A + 1, A + N);

    int lo = 0, hi = N;
    while (lo + 1 != hi) {
        int md = (lo + hi) / 2;
        if (chk(md)) hi = md;
        else lo = md;
    }

    printf("%d\n", A[hi]);
}
0