結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー Kmcode1Kmcode1
提出日時 2017-04-21 22:28:47
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,061 bytes
コンパイル時間 1,121 ms
コンパイル使用メモリ 152,524 KB
実行使用メモリ 8,960 KB
最終ジャッジ日時 2023-09-27 11:18:15
合計ジャッジ時間 5,011 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 269 ms
8,680 KB
testcase_08 AC 269 ms
8,592 KB
testcase_09 WA -
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 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;

#define MAX 100002

int n;
int m;

vector<int> v;

vector<int> vv;

multiset<int> s;
bool ok(int val){
	s.clear();
	for (int i = 0; i < vv.size(); i++){
		s.insert(vv[i]);
	}
	auto it = s.lower_bound(val);
	s.erase(it);
	int rankk = 0;
	while (!s.empty()){
		auto f = *s.rbegin();
		s.erase(s.lower_bound(f));
		int need = val+v[0] - f;
		need++;
		auto it = s.lower_bound(need);
		if (it != s.end()){
			s.erase(it);
			rankk++;
		}
		else{
			break;
		}
	}
	rankk++;
	return rankk <= m;
}
int main(){
	cin >> n >> m;
	for (int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		v.push_back(a);
		if (i)vv.push_back(a);
	}
	sort(vv.begin(), vv.end());
	int mint = 0;
	int maxt = vv.size() - 1;
	while (mint + 1 < maxt){
		int mid = (mint + maxt) >> 1;
		if (ok(vv[mid])){
			maxt = mid;
		}
		else{
			mint = mid;
		}
	}
	if (ok(mint)){
		cout <<vv[ mint] << endl;
	}
	else{
		if (ok(maxt)){
			cout << vv[maxt] << endl;
		}
		else{
			puts("-1");
		}
	}
	return 0;
}
0