結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー htensaihtensai
提出日時 2020-01-31 08:34:54
言語 Java21
(openjdk 21)
結果
AC  
実行時間 229 ms / 3,000 ms
コード長 1,723 bytes
コンパイル時間 2,139 ms
コンパイル使用メモリ 78,056 KB
実行使用メモリ 59,788 KB
最終ジャッジ日時 2023-10-17 08:12:56
合計ジャッジ時間 5,683 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
53,596 KB
testcase_01 AC 54 ms
53,592 KB
testcase_02 AC 55 ms
52,424 KB
testcase_03 AC 56 ms
52,440 KB
testcase_04 AC 55 ms
52,424 KB
testcase_05 AC 55 ms
53,584 KB
testcase_06 AC 54 ms
52,464 KB
testcase_07 AC 221 ms
58,960 KB
testcase_08 AC 216 ms
59,412 KB
testcase_09 AC 174 ms
58,324 KB
testcase_10 AC 178 ms
58,156 KB
testcase_11 AC 165 ms
58,476 KB
testcase_12 AC 183 ms
58,128 KB
testcase_13 AC 229 ms
59,788 KB
testcase_14 AC 217 ms
59,376 KB
testcase_15 AC 218 ms
59,556 KB
testcase_16 AC 213 ms
59,496 KB
testcase_17 AC 54 ms
53,588 KB
testcase_18 AC 54 ms
53,584 KB
testcase_19 AC 53 ms
53,584 KB
testcase_20 AC 53 ms
53,592 KB
権限があれば一括ダウンロードができます

ソースコード

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