結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー ありあり
提出日時 2023-02-21 11:09:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,292 bytes
コンパイル時間 1,034 ms
コンパイル使用メモリ 95,268 KB
実行使用メモリ 5,320 KB
最終ジャッジ日時 2023-09-29 05:06:17
合計ジャッジ時間 4,191 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 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,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 71 ms
4,992 KB
testcase_08 AC 73 ms
4,988 KB
testcase_09 AC 53 ms
4,924 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 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;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<pair<int, int>> b;
  for (int i = 1; i < n; i++) b.push_back({a[i], i});
  sort(b.begin(), b.end());
  //for (int i = 0; i < n-1; i++) cout << b[i].first << " " << b[i].second << endl;
  int ok = n-1;
  int ng = -1;
  while (ng+1 < ok) {
    int m = (ok+ng)/2;
    //printf("ng = %d, ok = %d, m = %d\n", ng, ok, m);
    vector<int> c;
    for (int i = 0; i < n-1; i++) if (i != m) c.push_back(b[i].first);
    vector<int> sums; 
    sums.push_back(a[0] + b[m].first);
    for (int i = 0; i < n-2; i += 2) sums.push_back(c[i] + c[i+1]);
    sort(sums.begin(), sums.end());
    //printf("sums : "); for (auto s : sums) printf("%d ", s); printf("\n");
    int r = sums.end() - upper_bound(sums.begin(), sums.end(), a[0] + b[m].first);
    //printf("r = %d\n", r);
    //printf("r < k = %d < %d\n", r, k);
    if (r < k) ok = m;
    else ng = m;
  }
  if (ok == n-1) cout << -1 << endl;
  else cout << b[ok].first << endl;
}
0