結果
| 問題 | No.507 ゲーム大会(チーム決め) | 
| コンテスト | |
| ユーザー |  tenten | 
| 提出日時 | 2021-03-08 19:39:19 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 737 ms / 3,000 ms | 
| コード長 | 1,268 bytes | 
| コンパイル時間 | 3,784 ms | 
| コンパイル使用メモリ | 77,004 KB | 
| 実行使用メモリ | 62,280 KB | 
| 最終ジャッジ日時 | 2024-10-10 11:33:46 | 
| 合計ジャッジ時間 | 13,082 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 19 | 
ソースコード
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]);
        }
    }
}
            
            
            
        