結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー hiyokko2hiyokko2
提出日時 2017-08-04 10:54:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 66 ms / 3,000 ms
コード長 1,400 bytes
コンパイル時間 1,583 ms
コンパイル使用メモリ 163,104 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 01:55:14
合計ジャッジ時間 2,728 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 66 ms
6,940 KB
testcase_08 AC 63 ms
6,944 KB
testcase_09 AC 49 ms
6,944 KB
testcase_10 AC 48 ms
6,940 KB
testcase_11 AC 55 ms
6,944 KB
testcase_12 AC 50 ms
6,940 KB
testcase_13 AC 64 ms
6,944 KB
testcase_14 AC 53 ms
6,944 KB
testcase_15 AC 54 ms
6,944 KB
testcase_16 AC 54 ms
6,944 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 1 ms
6,944 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;

int N, M;
int kScore;
int a[101010];

bool C(int idx)
{
    vector<int> vi;

    int sum = kScore + a[idx] + 1;
    //cout << "a[idx] = " << a[idx] << endl;
    //cout << "sum = " << sum << endl;

    REP(i,N) if (i != idx) vi.push_back(a[i]);
    //cout << "size = " << vi.size() << endl;
    int num = 0;
    int f = 0, e = N - 2;
    while (f < e) {
        if (vi[f] + vi[e] < sum) {
            f++;
            continue;
        }
        if (vi[f] + vi[e] >= sum) {
            f++;
            e--;
            num++;
            continue;
        }
    }

    //cout << "num = " << num << endl;

    return num < M;
}

signed main()
{
    cin >> N >> M;
    cin >> kScore;
    REP(i,N-1) cin >> a[i];

    a[N-1] = 0;
    a[N] = 3e9;
    sort(a, a + (N + 1));

    int lb = 0, ub = N;
    while (ub - lb > 1) {
        //cout << "ub = " << ub << " : lb = " << lb << endl;
        int mid = (lb + ub) / 2;
        if (C(mid)) {
            //cout << "true" << endl;
            ub = mid;
        } else {
            lb = mid;
            //cout << "false" << endl;
        }
    }

    if (ub == N) {
        cout << -1 << endl;
    } else {
        cout << a[ub] << endl;
    }
}
0