結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー Kmcode1Kmcode1
提出日時 2017-04-21 22:42:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 431 ms / 3,000 ms
コード長 1,071 bytes
コンパイル時間 1,469 ms
コンパイル使用メモリ 152,460 KB
実行使用メモリ 8,688 KB
最終ジャッジ日時 2023-09-27 11:26:30
合計ジャッジ時間 6,042 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 313 ms
8,684 KB
testcase_08 AC 347 ms
8,672 KB
testcase_09 AC 303 ms
8,644 KB
testcase_10 AC 339 ms
8,572 KB
testcase_11 AC 391 ms
8,600 KB
testcase_12 AC 302 ms
8,688 KB
testcase_13 AC 420 ms
8,632 KB
testcase_14 AC 422 ms
8,544 KB
testcase_15 AC 431 ms
8,512 KB
testcase_16 AC 409 ms
8,620 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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(vv[mint])){
		cout << vv[mint] << endl;
	}
	else{
		if (ok(vv[maxt])){
			cout << vv[maxt] << endl;
		}
		else{
			puts("-1");
		}
	}
	return 0;
}
0