結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー latte0119latte0119
提出日時 2017-04-21 22:27:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 284 ms / 3,000 ms
コード長 1,101 bytes
コンパイル時間 1,170 ms
コンパイル使用メモリ 150,344 KB
実行使用メモリ 8,880 KB
最終ジャッジ日時 2023-09-27 11:15:40
合計ジャッジ時間 5,504 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 248 ms
8,752 KB
testcase_08 AC 251 ms
8,788 KB
testcase_09 AC 255 ms
8,856 KB
testcase_10 AC 240 ms
8,788 KB
testcase_11 AC 246 ms
8,792 KB
testcase_12 AC 256 ms
8,736 KB
testcase_13 AC 284 ms
8,832 KB
testcase_14 AC 266 ms
8,880 KB
testcase_15 AC 262 ms
8,792 KB
testcase_16 AC 265 ms
8,852 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,M;
int A[111111];

bool C(int x){
    multiset<int>s;
    rep(i,N){
        if(i==0||i==x)continue;
        s.insert(A[i]);
    }

    int X=A[0]+A[x];

    int cnt=0;
    while(s.size()){
        int t=*s.rbegin();
        auto it=s.end();
        it--;
        s.erase(it);

        it=s.upper_bound(X-t);
        if(it==s.end())break;
        cnt++;
        s.erase(it);
    }

    return cnt<M;
}

signed main(){
    cin>>N>>M;
    rep(i,N)cin>>A[i];

    sort(A+1,A+N);
    int lb=0,ub=N;
    while(ub-lb>1){
        int mid=(ub+lb)/2;
        if(C(mid))ub=mid;
        else lb=mid;
    }

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