結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー face4
提出日時 2019-09-26 21:11:29
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 51 ms / 3,000 ms
コード長 910 bytes
コンパイル時間 657 ms
コンパイル使用メモリ 74,848 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-24 06:21:51
合計ジャッジ時間 1,829 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    int k;  cin >> k;
    vector<int> a(n-1);
    for(int i = 0; i < n-1; i++)  cin >> a[i];
    sort(a.begin(), a.end());
    auto f = [&](int pos)->bool{
        int score = a[pos] + k;
        int count = 0, l = 0, r = n-2;
        if(l == pos)    l++;
        if(r == pos)    r--;
        while(l < r){
            if(a[l]+a[r] > score){
                count++, l++, r--;
            }else{
                l++;
            }
            if(l == pos)    l++;
            if(r == pos)    r--;
        }
        return count >= m;
    };
    if(f(n-2)){
        cout << -1 << endl;
        return 0;
    }
    int l = -1, r = n-2;
    while(r-l > 1){
        int mid = (l+r)/2;
        if(f(mid))  l = mid;
        else        r = mid;
    }
    cout << a[r] << endl;
    return 0;
}
0