結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー tentententen
提出日時 2021-03-08 19:39:19
言語 Java21
(openjdk 21)
結果
AC  
実行時間 708 ms / 3,000 ms
コード長 1,268 bytes
コンパイル時間 2,728 ms
コンパイル使用メモリ 77,564 KB
実行使用メモリ 50,332 KB
最終ジャッジ日時 2024-04-18 18:13:39
合計ジャッジ時間 12,343 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 155 ms
41,868 KB
testcase_01 AC 139 ms
41,688 KB
testcase_02 AC 128 ms
41,272 KB
testcase_03 AC 126 ms
41,420 KB
testcase_04 AC 129 ms
41,324 KB
testcase_05 AC 129 ms
41,436 KB
testcase_06 AC 123 ms
41,960 KB
testcase_07 AC 696 ms
50,332 KB
testcase_08 AC 708 ms
49,328 KB
testcase_09 AC 531 ms
48,316 KB
testcase_10 AC 518 ms
48,400 KB
testcase_11 AC 558 ms
49,004 KB
testcase_12 AC 508 ms
48,440 KB
testcase_13 AC 698 ms
48,540 KB
testcase_14 AC 683 ms
48,552 KB
testcase_15 AC 678 ms
48,760 KB
testcase_16 AC 656 ms
48,792 KB
testcase_17 AC 119 ms
41,288 KB
testcase_18 AC 128 ms
41,920 KB
testcase_19 AC 125 ms
41,604 KB
testcase_20 AC 127 ms
42,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        int[] scores = new int[n + 1];
        scores[0] = Integer.MIN_VALUE;
        scores[n] = Integer.MAX_VALUE / 2;
        for (int i = 1; i < n; i++) {
            scores[i] = sc.nextInt();
        }
        Arrays.sort(scores);
        int left = 0;
        int right = n;
        while (right - left > 1) {
            int x = (left + right) / 2;
            int idx = 1;
            int count = 0;
            for (int i = n - 1; i > idx; i--) {
                if (i == x) {
                    continue;
                }
                while (scores[i] + scores[idx] <= scores[x] + k || idx == x) {
                    idx++;
                }
                if (idx < i) {
                    count++;
                    idx++;
                }
            }
            if (count < m) {
                right = x;
            } else {
                left = x;
            }
        }
        if (right == n) {
            System.out.println(-1);
        } else {
            System.out.println(scores[right]);
        }
    }
}
0