結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー ei1333333ei1333333
提出日時 2017-04-21 23:07:44
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 825 bytes
コンパイル時間 1,224 ms
コンパイル使用メモリ 147,188 KB
実行使用メモリ 8,652 KB
最終ジャッジ日時 2023-09-27 20:41:33
合計ジャッジ時間 3,589 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,376 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 RE -
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;

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 - A[*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];

  if(!check(A[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