結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー fjafjafjafjafjafja
提出日時 2017-09-21 17:43:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 803 ms / 3,000 ms
コード長 1,266 bytes
コンパイル時間 4,300 ms
コンパイル使用メモリ 78,148 KB
実行使用メモリ 59,700 KB
最終ジャッジ日時 2024-04-26 06:34:23
合計ジャッジ時間 12,564 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
54,432 KB
testcase_01 AC 132 ms
54,416 KB
testcase_02 AC 134 ms
54,336 KB
testcase_03 AC 131 ms
54,476 KB
testcase_04 AC 132 ms
54,180 KB
testcase_05 AC 133 ms
54,148 KB
testcase_06 AC 148 ms
54,160 KB
testcase_07 AC 803 ms
59,588 KB
testcase_08 AC 683 ms
59,664 KB
testcase_09 AC 569 ms
59,304 KB
testcase_10 AC 549 ms
59,196 KB
testcase_11 AC 588 ms
59,700 KB
testcase_12 AC 559 ms
59,484 KB
testcase_13 AC 750 ms
59,556 KB
testcase_14 AC 667 ms
59,620 KB
testcase_15 AC 691 ms
59,584 KB
testcase_16 AC 692 ms
59,624 KB
testcase_17 AC 134 ms
54,232 KB
testcase_18 AC 135 ms
54,272 KB
testcase_19 AC 132 ms
54,380 KB
testcase_20 AC 143 ms
54,476 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