結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー ei1333333ei1333333
提出日時 2017-04-21 23:15:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 372 ms / 3,000 ms
コード長 865 bytes
コンパイル時間 2,438 ms
コンパイル使用メモリ 149,872 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2023-09-27 23:16:57
合計ジャッジ時間 5,986 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 74 ms
8,412 KB
testcase_08 AC 291 ms
8,376 KB
testcase_09 AC 372 ms
8,416 KB
testcase_10 AC 309 ms
8,376 KB
testcase_11 AC 294 ms
8,392 KB
testcase_12 AC 359 ms
8,368 KB
testcase_13 AC 343 ms
8,444 KB
testcase_14 AC 319 ms
8,448 KB
testcase_15 AC 332 ms
8,384 KB
testcase_16 AC 334 ms
8,372 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long int64;

int N, M, K, A[100000];

bool check(int idx)
{
  multiset< int > vv;
  for(int i = 0; i < N; i++) {
    if(i != idx) {
      vv.emplace(A[i]);
    }
  }
  int64 beet = A[idx] + K;
  multiset< int >::iterator it = vv.begin();
  int ret = 0;

  while(it != vv.end()) {
    auto st = vv.upper_bound(beet - *it);
    if(it == st) ++st;
    if(st != vv.end()) {
      vv.erase(st), ++ret;
    }
    it = vv.erase(it);
  }
  return (ret < M);
}

int main()
{

  cin >> N >> M;
  --N;
  cin >> K;
  for(int i = 0; i < N; i++) cin >> A[i];
  sort(A, A + N);

  if(!check(N - 1)) {
    cout << -1 << endl;
    return (0);
  }

  int low = 0, high = N - 1;
  while(high - low > 0) {
    int mid = (low + high) / 2;
    if(check(mid)) high = mid;
    else low = mid + 1;
  }
  cout << A[low] << endl;
}
0