結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー uchiiiiuchiiii
提出日時 2019-04-01 02:44:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,374 bytes
コンパイル時間 1,614 ms
コンパイル使用メモリ 171,540 KB
実行使用メモリ 5,976 KB
最終ジャッジ日時 2024-05-03 03:53:39
合計ジャッジ時間 3,677 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;
    for(int i=20;i>=0;i--){
        if(solve(R-(1<<i))){
            R -= (1<<i);
        }
    }
    
    if(R = n-1) cout << -1 << endl;
    else cout << a[R] << endl;
    return 0;
}
0