結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー uchiiiiuchiiii
提出日時 2019-04-01 02:58:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 3,000 ms
コード長 1,409 bytes
コンパイル時間 1,602 ms
コンパイル使用メモリ 170,820 KB
実行使用メモリ 5,796 KB
最終ジャッジ日時 2023-08-15 17:19:14
合計ジャッジ時間 3,455 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 41 ms
4,848 KB
testcase_08 AC 49 ms
5,624 KB
testcase_09 AC 43 ms
5,676 KB
testcase_10 AC 44 ms
5,624 KB
testcase_11 AC 42 ms
5,624 KB
testcase_12 AC 43 ms
5,796 KB
testcase_13 AC 59 ms
5,644 KB
testcase_14 AC 48 ms
5,744 KB
testcase_15 AC 50 ms
5,628 KB
testcase_16 AC 49 ms
5,740 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define VI vector<int>
#define PII pair<int, int>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
const int INF=1<<30; const ll LINF=1LL<<60 ; const ll MOD=1e9+7 ;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//-------------------
const int MX = 100000 + 7;
ll a[MX];
int n,m;
int r, l; 

// number of the set whose value is bigger than mine.

bool solve(int now){
    if(now <= 0) return false;
    ll t = a[0] + a[now];
    vector<ll> v;
    FOR(i,1,n-1) if(i != now) v.push_back(a[i]);
    l = 0; r = v.size()-1;

    int num = 0;
    while(l<r){
        while(v[l]+v[r] <= t && l<r){
            l++;
        }
        if(l<r) {num += 1; l++; r--;}
    }
    return num <= m-1;
}

int main(){
    cin >> n >> m;

    FOR(i,0,n-1){
        cin >> a[i];
    }
    sort(a+1, a+n);

    int R = n-1;
    if(solve(R) == false){
        cout << -1 << endl; return 0;
    }
    for(int i=20;i>=0;i--){
        if(solve(R-(1<<i))){
            R -= (1<<i);
        }
    }
    
    
    cout << a[R] << endl;
    return 0;
}
0