結果

問題 No.794 チーム戦 (2)
ユーザー tentententen
提出日時 2020-09-02 23:00:47
言語 Java
(openjdk 23)
結果
AC  
実行時間 927 ms / 1,500 ms
コード長 929 bytes
コンパイル時間 2,443 ms
コンパイル使用メモリ 75,028 KB
実行使用メモリ 65,240 KB
最終ジャッジ日時 2024-11-22 00:18:17
合計ジャッジ時間 22,889 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static final int MOD = 1000000007;
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int k = sc.nextInt();
    	int[] arr = new int[n];
    	for (int i = 0; i < n; i++) {
    	    arr[i] = sc.nextInt();
    	}
    	Arrays.sort(arr);
    	long ans = 1;
    	if (k - arr[n - 1] < arr[0]) {
    	    System.out.println(0);
    	    return;
    	}
    	int right = n - 1;
    	int left = 0;
    	int count = 0;
    	while (right >= n / 2) {
    	    while (left + 1 < right && k - arr[right] >= arr[left + 1]) {
    	        left++;
    	    }
    	    if (left + 1 <= count) {
    	        System.out.println(0);
    	        return;
    	    }
    	    ans *= left + 1 - count;
    	    ans %= MOD;
    	    count++;
    	    right--;
    	    left = Math.min(left, right - 1);
    	}
    	System.out.println(ans);
	}
}
0