結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー tubo28tubo28
提出日時 2017-06-09 15:27:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,407 bytes
コンパイル時間 3,490 ms
コンパイル使用メモリ 206,448 KB
実行使用メモリ 13,448 KB
最終ジャッジ日時 2023-10-23 20:51:26
合計ジャッジ時間 14,802 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
4,372 KB
testcase_06 WA -
testcase_07 WA -
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;
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...);
}
#define dump(...)                                         \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \
        __dump__(os, __VA_ARGS__);                        \
        std::cerr << os.str() << std::endl;               \
    } while (0)

int main() {
    int n, m;
    while (cin >> n >> m) {
        int a[100010];
        --n;
        int x;
        cin >> x;
        rep(i, n) {
            cin >> a[i];
        }
        // dump("a");
        // rep(i, n) cout << a[i] << ' ';
        // cout << endl;
        int lo = -1, hi = n;
        while (lo + 1 < hi) {
            int mid = lo + (hi - lo) / 2;
            multiset<int> s;
            rep(i, n) {
                if (i != mid) s.insert(a[i]);
            }
            auto will_win = [&]() {
                if (x < 0) return false;
                int our = x + a[mid];
                // dump(x, a[mid]);
                multiset<int> s;
                rep(i, n) if (mid != i) s.insert(a[i]);
                rep(i, n/2 - m) {
                    int a = *s.rbegin();
                    s.erase(s.find(a));
                    // dump(a);
                    auto bi = s.upper_bound(our - a);
                    if (bi == s.end()) {
                        return true;
                    }
                    // dump(a, *bi);
                    s.erase(bi);
                }
                return false;
            };
            
            if (will_win()) {
                hi= mid;
            } else {
                lo = mid;
            }
        }
        int ans = hi == n ? -1 : a[hi];
        cout << ans << endl;
    }
}
0