結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー あり
提出日時 2023-02-21 12:30:22
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 951 bytes
コンパイル時間 750 ms
コンパイル使用メモリ 95,520 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-22 00:35:30
合計ジャッジ時間 2,347 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 8 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#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> s;
    s.push_back(x+a[m]);
    for (int i = 0; i < n-1; i++) {
      if (i == m) continue;
      if (s.back() > 0) s.push_back(-a[i]);
      else s.back() = -s.back() + a[i];
    }
    sort(s.begin(), s.end());
    int r = s.end() - upper_bound(s.begin(), s.end(), x+a[m]);
    if (r < k) ok = m;
    else ng = m;
  }
  if (ok == n-1) cout << -1 << endl;
  else cout << a[ok] << endl;
}
0