結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー htensaihtensai
提出日時 2020-01-31 08:34:00
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,729 bytes
コンパイル時間 3,562 ms
コンパイル使用メモリ 82,404 KB
実行使用メモリ 60,676 KB
最終ジャッジ日時 2023-10-17 08:12:40
合計ジャッジ時間 7,954 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
53,752 KB
testcase_01 AC 55 ms
53,740 KB
testcase_02 AC 54 ms
53,736 KB
testcase_03 WA -
testcase_04 AC 55 ms
52,652 KB
testcase_05 AC 54 ms
53,756 KB
testcase_06 WA -
testcase_07 AC 220 ms
59,160 KB
testcase_08 WA -
testcase_09 AC 175 ms
58,324 KB
testcase_10 AC 176 ms
58,528 KB
testcase_11 AC 165 ms
57,892 KB
testcase_12 AC 174 ms
58,636 KB
testcase_13 AC 237 ms
59,736 KB
testcase_14 AC 218 ms
59,292 KB
testcase_15 AC 216 ms
59,872 KB
testcase_16 AC 219 ms
59,608 KB
testcase_17 AC 55 ms
53,752 KB
testcase_18 AC 57 ms
53,756 KB
testcase_19 AC 55 ms
53,740 KB
testcase_20 AC 55 ms
53,744 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