結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー ありあり
提出日時 2023-02-21 12:30:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 951 bytes
コンパイル時間 854 ms
コンパイル使用メモリ 88,464 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-29 06:05:27
合計ジャッジ時間 2,783 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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