結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー ありあり
提出日時 2023-02-21 13:35:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 3,000 ms
コード長 1,046 bytes
コンパイル時間 857 ms
コンパイル使用メモリ 88,240 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-29 06:41:55
合計ジャッジ時間 2,422 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 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 2 ms
4,380 KB
testcase_07 AC 58 ms
4,376 KB
testcase_08 AC 57 ms
4,460 KB
testcase_09 AC 42 ms
4,380 KB
testcase_10 AC 41 ms
4,384 KB
testcase_11 AC 40 ms
4,376 KB
testcase_12 AC 41 ms
4,500 KB
testcase_13 AC 58 ms
4,376 KB
testcase_14 AC 46 ms
4,380 KB
testcase_15 AC 46 ms
4,380 KB
testcase_16 AC 46 ms
4,384 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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> 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;
}
0