結果
| 問題 | No.507 ゲーム大会(チーム決め) | 
| コンテスト | |
| ユーザー |  dnish | 
| 提出日時 | 2018-03-06 12:38:31 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 49 ms / 3,000 ms | 
| コード長 | 1,320 bytes | 
| コンパイル時間 | 681 ms | 
| コンパイル使用メモリ | 85,124 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-09-16 08:50:41 | 
| 合計ジャッジ時間 | 2,073 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 19 | 
ソースコード
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const ll inf = 1e10;
int N, M;
int a[100010];
bool C(int mid){//index
    int mn=1;
    int mx=N-1;
    int cnt=0;
    int X = a[0] + a[mid];
    while(mx - mn>0){
       if(mx == mid) {
           mx--;continue;
       }
       if(mn == mid){
           mn++;continue;
       }
       if(a[mx] + a[mn] > X){
           cnt++;
           mx--;
           mn++;
       }else{
           mn++;
       }
    }
    //lbが更新される不等式を書く
    return cnt < M;
}
int nibutan(){
    int lb=0,ub=N;
    while(ub-lb>1){
        int mid=(lb+ub)/2;
        if(C(mid)) ub=mid;
        else lb=mid;
        //cout<<lb<<" "<<ub<<endl;
    }
    return a[ub];
}
int main(){
    cin>>N>>M;
    REP(i,0,N) cin>>a[i];
    if(N==2) {
        p(a[1]);
        return 0;
    }
    sort(a+1,a+N);
    a[N]=-1;
    int ans = nibutan();
    p(ans);
    return 0;
}
            
            
            
        