結果

問題 No.507 ゲーム大会(チーム決め)
コンテスト
ユーザー bal4u
提出日時 2019-08-20 14:24:59
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 19 ms / 3,000 ms
コード長 1,097 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 172 ms
コンパイル使用メモリ 39,492 KB
最終ジャッジ日時 2026-02-22 04:24:14
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// yukicoder: No.507 ゲーム大会(チーム決め)
// bal4u 2019.8.20

#include <stdio.h>
#include <stdlib.h>

//// 入出力関係
#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() { // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

int N, M;
int a[100005];

int cmp(const void *u, const void *v) { return *(int *)u - *(int *)v; }
	
int ok(int x, int id) {
	int i, j, n = 0;
	j = N-1; for (i = 1; i < j; i++) {
		if (j == id) j--;
		while (i < j && a[i] + a[j] < x) i++;
		if (i < j) { if (++n >= M) return 0; }
		j--;
	}
	return 1;
}

int resolv() {
	int t, x, f = 0;
	int m, l = 1, r = N;
	
    while (l+1 < r) {
        m = (l+r) >> 1;
		x = a[m], a[m] = 0;
		t = ok(a[0]+x, m);
		f |= t, a[m] = x;
        if (t) r = m; else l = m;
    }
	if (!f) return -1;
	return a[r];
}

int main()
{
	int i, ans;

	N = in(), M = in();
	for (i = 0; i < N; i++) a[i] = in();
	qsort(a+1, N-1, sizeof(int), cmp);
	if (N == M*2) ans = a[1];
	else a[0]++, ans = resolv();
	printf("%d\n", ans);
	return 0;
}
0