結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー parukiparuki
提出日時 2017-04-21 23:16:59
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 325 ms / 3,000 ms
コード長 1,498 bytes
コンパイル時間 1,437 ms
コンパイル使用メモリ 170,656 KB
実行使用メモリ 8,688 KB
最終ジャッジ日時 2023-09-27 23:18:49
合計ジャッジ時間 5,197 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 43 ms
8,648 KB
testcase_08 AC 289 ms
8,420 KB
testcase_09 AC 325 ms
8,440 KB
testcase_10 AC 289 ms
8,576 KB
testcase_11 AC 292 ms
8,688 KB
testcase_12 AC 303 ms
8,672 KB
testcase_13 AC 321 ms
8,584 KB
testcase_14 AC 300 ms
8,412 KB
testcase_15 AC 299 ms
8,488 KB
testcase_16 AC 297 ms
8,436 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

int N, M;
int a[100001];

int f(int x) {
    multiset<int> y;
    FOR(i, 1, N)if (i != x) {
        y.insert(a[i]);
    }
    int me = a[x] + a[0], ra = 1;
    while (sz(y) > 1) {
        auto p = --y.end();
        int u = *p;
        y.erase(p);
        auto q = y.lower_bound(me - u + 1);
        if (q == y.end()) {
            break;
        }
        else {
            ra++;
            y.erase(q);
            if (ra > M)return 0;
        }
    }
    return 1;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    while (cin >> N >> M) {
        rep(i, N)cin >> a[i];

        sort(a + 1, a + N);
        if (!f(N - 1)) {
            cout << -1 << endl;
            continue;
        }
        else {
            int ok = N - 1, ng = 0, mid;
            while (ok - ng > 1) {
                mid = (ok + ng) / 2;
                (f(mid) ? ok : ng) = mid;
            }
            cout << a[ok] << endl;
        }
    }
}
0