結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー eye_engineeye_engine
提出日時 2019-10-24 19:58:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 55 ms / 3,000 ms
コード長 1,777 bytes
コンパイル時間 1,057 ms
コンパイル使用メモリ 106,680 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 03:21:17
合計ジャッジ時間 2,478 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 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,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 52 ms
4,380 KB
testcase_08 AC 55 ms
4,380 KB
testcase_09 AC 33 ms
4,380 KB
testcase_10 AC 35 ms
4,380 KB
testcase_11 AC 36 ms
4,380 KB
testcase_12 AC 33 ms
4,376 KB
testcase_13 AC 55 ms
4,380 KB
testcase_14 AC 43 ms
4,376 KB
testcase_15 AC 43 ms
4,380 KB
testcase_16 AC 44 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 62;

int main() {
  //
  ll n, m;
  cin >> n >> m;
  ll k;
  cin >> k;
  vl a(n - 1);
  rep(i, n - 1) { cin >> a[i]; }
  sort(ALL(a));
  ll ok = n - 1;
  ll ng = -1;
  while (ok - ng > 1) {
    ll mid = (ok + ng) / 2;
    ll val = k + a[mid];
    vector<bool> used(n - 1, false);
    used[mid] = true;
    ll cnt = 0;
    ll left = 0;
    ll right = n - 2;
    // cerr << ng << ":" << ok << ":" << mid << ":" << val << endl;
    while (right - left > 1) {
      while (right > 0 && used[right]) right--;
      while (left < right && (used[left] || a[right] + a[left] <= val)) left++;
      if (left < right && !used[left] && !used[right] &&
          a[left] + a[right] > val) {
        cnt++;
        used[right] = true;
        used[left] = true;
        // cerr << "!" << a[left] << "+" << a[right] << endl;
      }
    }
    // cerr << cnt << endl;
    if (cnt >= m) {
      ng = mid;
    } else {
      ok = mid;
    }
  }
  if (0 <= ok && ok < n - 1) {
    cout << a[ok] << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
0