結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー fjafjafjafjafjafja
提出日時 2017-09-21 17:43:47
言語 Java19
(openjdk 21)
結果
AC  
実行時間 648 ms / 3,000 ms
コード長 1,266 bytes
コンパイル時間 3,453 ms
コンパイル使用メモリ 74,488 KB
実行使用メモリ 63,152 KB
最終ジャッジ日時 2023-08-08 13:50:04
合計ジャッジ時間 11,545 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
56,080 KB
testcase_01 AC 120 ms
56,148 KB
testcase_02 AC 121 ms
56,596 KB
testcase_03 AC 118 ms
55,852 KB
testcase_04 AC 119 ms
56,412 KB
testcase_05 AC 118 ms
55,748 KB
testcase_06 AC 118 ms
55,900 KB
testcase_07 AC 596 ms
62,376 KB
testcase_08 AC 593 ms
62,292 KB
testcase_09 AC 525 ms
60,564 KB
testcase_10 AC 528 ms
60,952 KB
testcase_11 AC 535 ms
61,024 KB
testcase_12 AC 519 ms
60,708 KB
testcase_13 AC 648 ms
63,152 KB
testcase_14 AC 564 ms
63,016 KB
testcase_15 AC 564 ms
60,996 KB
testcase_16 AC 594 ms
58,616 KB
testcase_17 AC 122 ms
55,948 KB
testcase_18 AC 122 ms
55,992 KB
testcase_19 AC 117 ms
56,176 KB
testcase_20 AC 117 ms
56,120 KB
権限があれば一括ダウンロードができます

ソースコード

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);
		//for(int aa:a){System.out.print(aa);}System.out.println();
		if(isok(min)){ans=a[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;}//System.out.println("ind="+ans+" true");}
				else{min=ans;}//System.out.println("ind="+ans+" false");}
			}
			ans=a[max];
		}
		System.out.println(ans);



	}
	static boolean isok(int ind)
	{
		int me=k+a[ind];
		int rank=1,buf=-1;
		int end=0;
		//System.out.println("ind="+ind);
		for(int i=n-2;i>=0;i--)
		{
			if(ind==i){continue;}
			for(int j=buf+1;j<i;j++)
			{
				if(ind==j){continue;}
				buf=j;
				if(me<a[i]+a[j]){rank++;break;}//System.out.println("a["+i+"]+a["+j+"]="+(a[i]+a[j])+"は"+(rank-1)+"位");break;}
			}
		}
		return rank<=m;
	}
}
0