結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー dnishdnish
提出日時 2018-03-06 12:38:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 3,000 ms
コード長 1,320 bytes
コンパイル時間 848 ms
コンパイル使用メモリ 83,372 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 14:12:42
合計ジャッジ時間 2,179 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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;
}
0