結果
| 問題 | No.507 ゲーム大会(チーム決め) | 
| コンテスト | |
| ユーザー |  ei1333333 | 
| 提出日時 | 2017-04-21 23:15:17 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 429 ms / 3,000 ms | 
| コード長 | 865 bytes | 
| コンパイル時間 | 1,835 ms | 
| コンパイル使用メモリ | 164,088 KB | 
| 実行使用メモリ | 8,576 KB | 
| 最終ジャッジ日時 | 2024-07-20 17:40:52 | 
| 合計ジャッジ時間 | 5,814 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 19 | 
ソースコード
#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;
}
            
            
            
        