結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー face4face4
提出日時 2019-09-26 21:11:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 3,000 ms
コード長 910 bytes
コンパイル時間 646 ms
コンパイル使用メモリ 74,728 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 15:48:06
合計ジャッジ時間 1,831 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 49 ms
4,348 KB
testcase_08 AC 51 ms
4,348 KB
testcase_09 AC 33 ms
4,348 KB
testcase_10 AC 33 ms
4,348 KB
testcase_11 AC 32 ms
4,348 KB
testcase_12 AC 33 ms
4,348 KB
testcase_13 AC 51 ms
4,348 KB
testcase_14 AC 39 ms
4,348 KB
testcase_15 AC 39 ms
4,348 KB
testcase_16 AC 39 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

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