結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー どららどらら
提出日時 2017-04-21 23:46:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,222 bytes
コンパイル時間 1,619 ms
コンパイル使用メモリ 170,008 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-28 11:25:38
合計ジャッジ時間 3,008 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 73 ms
4,380 KB
testcase_08 WA -
testcase_09 AC 56 ms
4,380 KB
testcase_10 AC 55 ms
4,384 KB
testcase_11 AC 52 ms
4,380 KB
testcase_12 AC 56 ms
4,376 KB
testcase_13 AC 72 ms
4,380 KB
testcase_14 AC 65 ms
4,376 KB
testcase_15 AC 63 ms
4,380 KB
testcase_16 AC 63 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int N, M;

bool C(int x, int mid, vector<int>& v){
  int m = x + v[mid];
  int ret = 0;
  vector<int> w;
  rep(i,v.size()){
    if(i==mid) continue;
    w.push_back(v[i]);
  }
  sort(ALLOF(w));
  int a=0, b=w.size()-1;
  while(a<b){
    while(a<b && w[a]+w[b]<=m) a++;
    if(a<b && w[a]+w[b]>m){
      ret++;
      a++;
      b--;
    }
  }
  return ret < M;
}


int main(){
  cin >> N >> M;
  vector<int> v;
  int x;
  cin >> x;
  rep(i,N-1){
    int a;
    cin >> a;
    v.push_back(a);
  }
  if(N==2){
    cout << v[0] << endl;
    return 0;
  }
  sort(ALLOF(v));
  int ret = 1000000005;
  int lb = 0, ub = v.size();
  while(ub-lb>1){
    int mid = (lb+ub)/2;
    bool flg = C(x, mid, v);
    //cout << " " << mid << " " << flg << endl;
    if(flg){
      ret = min(ret, v[mid]);
    }
    if(flg) ub = mid;
    else lb = mid;
  }
  if(ret == 1000000005) cout << -1 << endl;
  else cout << ret << endl;
  return 0;
}
0