結果
| 問題 | No.507 ゲーム大会(チーム決め) | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-02-21 13:35:50 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 62 ms / 3,000 ms | 
| コード長 | 1,046 bytes | 
| コンパイル時間 | 981 ms | 
| コンパイル使用メモリ | 95,796 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-22 01:13:59 | 
| 合計ジャッジ時間 | 2,411 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 19 | 
ソースコード
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cassert>
#include <cmath>
#include <bitset>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int x;
  cin >> x;
  vector<int> a(n-1);
  for (int i = 0; i < n-1; i++) cin >> a[i];
  sort(a.begin(), a.end());
  int ng = -1;
  int ok = n-1;
  while (ng+1 < ok) {
    int m = (ng+ok)/2;
    //printf("ng = %d, ok = %d, m = %d\n", ng, ok, m);
    vector<int> b;
    for (int i = 0; i < n-1; i++)
      if (i != m) b.push_back(a[i]);
    //cout << "b : "; for (auto bb : b) cout << bb << " "; cout << endl;
    int cnt = 0;
    int l = 0, r = n-3;
    while (l < r) {
      if (b[l]+b[r] > x+a[m]) {
        l++;
        r--;
        cnt++;
      }
      else {
        l++;
      }
    }
    //cout << "cnt = " << cnt << endl;
    if (cnt < k) ok = m;
    else ng = m;
  }
  if (ok == n-1) cout << -1 << endl;
  else cout << a[ok] << endl;
}
            
            
            
        