結果
| 問題 | No.507 ゲーム大会(チーム決め) | 
| コンテスト | |
| ユーザー |  hiyokko2 | 
| 提出日時 | 2017-08-04 10:54:31 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 70 ms / 3,000 ms | 
| コード長 | 1,400 bytes | 
| コンパイル時間 | 1,627 ms | 
| コンパイル使用メモリ | 162,312 KB | 
| 実行使用メモリ | 5,856 KB | 
| 最終ジャッジ日時 | 2024-10-11 20:45:26 | 
| 合計ジャッジ時間 | 2,682 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 19 | 
ソースコード
#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;
    }
}
            
            
            
        