結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー fjafjafjafjafjafja
提出日時 2017-09-21 17:14:31
言語 Java19
(openjdk 21)
結果
WA  
実行時間 -
コード長 998 bytes
コンパイル時間 3,046 ms
コンパイル使用メモリ 74,424 KB
実行使用メモリ 66,384 KB
最終ジャッジ日時 2023-08-08 13:47:44
合計ジャッジ時間 11,387 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,724 KB
testcase_01 AC 115 ms
56,252 KB
testcase_02 WA -
testcase_03 AC 119 ms
55,812 KB
testcase_04 WA -
testcase_05 AC 117 ms
55,484 KB
testcase_06 WA -
testcase_07 AC 587 ms
62,404 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 508 ms
60,680 KB
testcase_11 AC 524 ms
61,240 KB
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 #

package yukicoder;

import java.util.Arrays;
import java.util.Scanner;

public class N507
{
	static int[] a,buf;
	static int k,n,m,ans;
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		n=sc.nextInt();
		m=sc.nextInt();
		int min=0,max=n-2;
		a=new int[n-1];
		k=sc.nextInt();//k a[0]-a[n-2]
		for(int i=0;i<n-1;i++)
		{
			a[i]=sc.nextInt();
		}
		Arrays.sort(a);

		if(isok(min)){ans=min;}
		else if(!isok(max)){ans=-1;}
		else
		{
			ans=(int)Math.ceil((min+max)/2);
			while(max-min>1)
			{
				//System.out.println("min max"+min+" "+max);
				ans=(int)Math.ceil((min+max)/2);
				if(isok(ans)){max=ans;}
				else{min=ans;}
			}
			ans=a[ans];
		}
		System.out.println(ans);



	}
	static boolean isok(int ind)//
	{
		int me=k+a[ind];
		int rank=1,buf=0;
		int end=0;

		for(int i=n-2;i>=0;i--)
		{
			if(ind==i){continue;}
			for(int j=buf;j<i;j++)
			{
				if(ind==j){continue;}
				buf=j;
				if(me<a[i]+a[j]){rank++;break;}
			}
		}
		return rank<=m;
	}
}
0