結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー tubo28tubo28
提出日時 2017-06-09 16:00:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 391 ms / 3,000 ms
コード長 2,530 bytes
コンパイル時間 1,945 ms
コンパイル使用メモリ 174,336 KB
実行使用メモリ 8,744 KB
最終ジャッジ日時 2023-10-23 20:53:58
合計ジャッジ時間 6,321 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 1 ms
4,372 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 367 ms
8,744 KB
testcase_08 AC 357 ms
8,744 KB
testcase_09 AC 350 ms
8,744 KB
testcase_10 AC 336 ms
8,744 KB
testcase_11 AC 358 ms
8,744 KB
testcase_12 AC 338 ms
8,744 KB
testcase_13 AC 391 ms
8,744 KB
testcase_14 AC 384 ms
8,744 KB
testcase_15 AC 387 ms
8,744 KB
testcase_16 AC 388 ms
8,744 KB
testcase_17 AC 2 ms
4,372 KB
testcase_18 AC 2 ms
4,372 KB
testcase_19 AC 1 ms
4,372 KB
testcase_20 AC 1 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, int(n) + 1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
const int MOD = 1000000007;

template <typename T>
void __dump__(std::ostream &os, const T &first) {
    os << first;
}
template <typename First, typename... Rest>
void __dump__(std::ostream &os, const First &first, const Rest &... rest) {
    os << first << ", ";
    __dump__(os, rest...);
}
#ifdef LOCAL
#define dump(...)                                         \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \
        __dump__(os, __VA_ARGS__);                        \
        std::cerr << os.str() << std::endl;               \
    } while (0)
#else
#define dump(...)
#endif

int main() {
    int n, m;
    while (cin >> n >> m) {
        int a[100010];
        --n;
        int x;
        cin >> x;
        rep(i, n) {
            cin >> a[i];
        }
        sort(a, a+n);

        // dump("a");
        // rep(i, n) cout << a[i] << ' ';
        // cout << endl;

        auto will_win = [&](int other) {
            if (other < 0) return false;
            int our = x + a[other];
            dump(other, our);
            // dump(x, a[other]);
            multiset<int> s;
            rep(i, n) if (other != i) s.insert(a[i]);
            //dump(n/2-m+1);
            rep(i, m) {
                if (s.size() == 0) return true;
                int a = *s.rbegin();
                s.erase(s.find(a));
                // dump(a);
                //dump(our - a);
                auto bi = s.upper_bound(our - a);
                if (bi == s.end()) {
                    //dump("true");
                    return true;
                }
                dump(a, *bi);
                s.erase(bi);
            }
            //dump("false");
            return false;
        };

        rep(i, n) dump(will_win(i));

        int lo = -1, hi = n;
        while (lo + 1 < hi) {
            int mid = lo + (hi - lo) / 2;
            if (will_win(mid)) {
                hi= mid;
            } else {
                lo = mid;
            }
        }
        int ans = hi == n ? -1 : a[hi];
        cout << ans << endl;
    }
}
0