結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー kotamanegikotamanegi
提出日時 2017-04-21 23:20:32
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,020 bytes
コンパイル時間 670 ms
コンパイル使用メモリ 90,552 KB
実行使用メモリ 4,788 KB
最終ジャッジ日時 2023-09-27 23:20:56
合計ジャッジ時間 3,066 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 52 ms
4,736 KB
testcase_08 WA -
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 #

#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define LONG_INF 10000000000000000
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
long long n, m;
vector<long long> a;
int judge(long long now) {
	int reco[200000] = {};
	int ok_cnt = -1;
	long long nya = 0;
	for (int i = 0;i < n;++i) {
		if (reco[i] == false) {
			int top = n - 1;
			int bot = 0;
			reco[i] = true;
			while (top - bot > 1) {
				int mid = top + bot;
				mid /= 2;
				if (reco[mid] == false && a[mid] >= now - a[i]) bot = mid;
				else top = mid;
			}
			if (reco[top] == false && a[top] >= now - a[i]) {
				reco[top] = true;
				if (a[top] == now - a[i]) {
					ok_cnt++;
				}
			}
			else if (reco[bot] == false && a[bot] >= now - a[i]) {
				reco[bot] = true;
				if (a[bot] == now - a[i]) {
					ok_cnt++;
				}
			}
			else {
				if (i - max(ok_cnt, 0) - nya <= m) {
					return true;
				}
				else return false;
			}
		}
		else {
			nya++;
		}
	}
	if (n - max(ok_cnt, 0) -nya <= m) {
		return true;
	}
	else return false;
}
int main() {
	cin >> n >> m;
	REP(i, n) {
		long long hoge;
		cin >> hoge;
		a.push_back(hoge);
	}
	long long k = a[0];
	sort(a.begin(), a.end(), greater<long long>());
	//binary_search
	long long top = 3000000000;
	long long bot = 0;
	while (top - bot > 1) {
		long long mid = (top + bot) / 2;
		if (judge(mid)) {
			top = mid;
		}else{
			bot = mid;
		}
	}
	if (judge(top)) {
		if (top - k <= a[0]) {
			cout << top - k << endl;
		}
		else cout << -1 << endl;
		return 0;
	}
	else {
		if (bot - k <= a[0]) {
			cout << bot - k << endl;
		}
		else cout << -1 << endl;
		return 0;
	}
}
0