結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー htensai
提出日時 2020-01-31 08:34:00
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,729 bytes
コンパイル時間 2,356 ms
コンパイル使用メモリ 79,932 KB
実行使用メモリ 56,884 KB
最終ジャッジ日時 2024-09-17 06:45:03
合計ジャッジ時間 6,498 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 16 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    static int[] dp;
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] first = br.readLine().split(" ", 2);
        int n = Integer.parseInt(first[0]);
        int mm = Integer.parseInt(first[1]);
        int mine = Integer.parseInt(br.readLine());
        int[] points = new int[n - 1];
        for (int i = 0; i < n - 1; i++) {
            points[i] = Integer.parseInt(br.readLine());
        }
        Arrays.sort(points);
        int left = 0;
        int right = n - 2;
        if (check(right, mine + points[right], points) >= mm) {
            System.out.println(-1);
            return;
        }
        if (check(left, mine + points[left], points) < mm) {
            System.out.println(points[left] + ":");
            return;
        }
        while (right - left > 1) {
            int m = (left + right) / 2;
            if (check(m, mine + points[m], points) >= mm) {
                left = m;
            } else {
                right = m;
            }
        }
        System.out.println(points[right]);
    }
    
    static int check(int target, int score, int[] arr) {
        int left = 0;
        int right = arr.length - 1;
        int count = 0;
        while (left < right) {
            if (left == target) {
                left++;
            } else if(right == target) {
                right--;
            } else if (arr[left] + arr[right] <= score) {
                left++;
            } else {
                count++;
                left++;
                right--;
            }
        }
        return count;
    }
}
0