結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー fjafjafjafjafjafja
提出日時 2017-09-21 17:21:16
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,081 bytes
コンパイル時間 3,427 ms
コンパイル使用メモリ 80,832 KB
実行使用メモリ 67,648 KB
最終ジャッジ日時 2023-08-08 13:48:09
合計ジャッジ時間 12,483 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 118 ms
56,208 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 600 ms
61,124 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 #

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;}//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=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